File: extensions.rb

package info (click to toggle)
mkvtoolnix 92.0-1
  • links: PTS
  • area: main
  • in suites: trixie
  • size: 58,620 kB
  • sloc: cpp: 216,810; ruby: 11,403; xml: 8,058; ansic: 6,885; sh: 4,884; python: 1,041; perl: 191; makefile: 113; awk: 16; javascript: 4
file content (80 lines) | stat: -rw-r--r-- 1,533 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
class NilClass
  def to_bool
    false
  end

  def blank?
    true
  end
end

class String
  def to_bool
    %w{1 true yes}.include? self.downcase
  end

  def blank?
    empty?
  end

  def to_c_string
  '"' + self.gsub(%r{"}, '\"') + '"'
  end

  def to_u8_c_string
    to_c_string # 'u8' + self.to_c_string
  end

  def to_cpp_string
    self.to_c_string + "s"
  end

  def to_u8_cpp_string
    to_cpp_string # "u8" + self.to_c_string + "s"
  end
end

class TrueClass
  def to_bool
    self
  end
end

class FalseClass
  def to_bool
    self
  end
end

class Array
  def to_hash_by key = nil, value = nil, &block
    elements = case
               when block_given? then self.collect(&block)
               when key.nil? then     self.collect { |e| [ e, true ] }
               else                   self.collect { |e| e.is_a?(Hash) ? [ e[key], value.nil? ? e : e[value] ] : [ e.send(key), value.nil? ? e : e.send(value) ] }
               end

    return Hash[ *elements.flatten ]
  end

  def for_target!
    self.flatten!

    reject = {
      :linux   => %w{      macos      windows},
      :macos   => %w{linux            windows x11},
      :windows => %w{linux macos unix         x11},
    }

    # Treat other OS (e.g. FreeBSD) the same as Linux wrt. which files to compile
    os    = $building_for.keys.select { |key| $building_for[key] }.first
    types = reject[os || :linux]

    re    = '(?:' + types.join('|') + ')'
    re    = %r{(?:/|^)#{re}[_.]}

    self.reject! { |f| re.match f }

    return self
  end
end