Class: Hbc::Container::Criteria

Inherits:
Object
  • Object
show all
Defined in:
Library/Homebrew/cask/lib/hbc/container/criteria.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, command) ⇒ Criteria

Returns a new instance of Criteria



6
7
8
9
# File 'Library/Homebrew/cask/lib/hbc/container/criteria.rb', line 6

def initialize(path, command)
  @path = path
  @command = command
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command



4
5
6
# File 'Library/Homebrew/cask/lib/hbc/container/criteria.rb', line 4

def command
  @command
end

#pathObject (readonly)

Returns the value of attribute path



4
5
6
# File 'Library/Homebrew/cask/lib/hbc/container/criteria.rb', line 4

def path
  @path
end

Instance Method Details

#extension(regex) ⇒ Object



11
12
13
# File 'Library/Homebrew/cask/lib/hbc/container/criteria.rb', line 11

def extension(regex)
  path.extname.sub(/^\./, "") =~ Regexp.new(regex.source, regex.options | Regexp::IGNORECASE)
end

#magic_number(regex) ⇒ Object



15
16
17
18
19
20
21
# File 'Library/Homebrew/cask/lib/hbc/container/criteria.rb', line 15

def magic_number(regex)
  return false if path.directory?

  # 262: length of the longest regex (currently: Hbc::Container::Tar)
  @magic_number ||= File.open(path, "rb") { |f| f.read(262) }
  @magic_number.match?(regex)
end