2016-09-24 13:52:43 +02:00
|
|
|
module Hbc
|
|
|
|
class Container
|
|
|
|
class Criteria
|
|
|
|
attr_reader :path, :command
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def initialize(path, command)
|
|
|
|
@path = path
|
|
|
|
@command = command
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def extension(regex)
|
2016-10-14 20:03:34 +02:00
|
|
|
path.extname.sub(/^\./, "") =~ Regexp.new(regex.source, regex.options | Regexp::IGNORECASE)
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def magic_number(regex)
|
|
|
|
# 262: length of the longest regex (currently: Hbc::Container::Tar)
|
2017-08-07 14:31:56 -07:00
|
|
|
@magic_number ||= File.open(@path, "rb") { |f| f.read(262) }
|
|
|
|
@magic_number =~ regex
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|