23 lines
550 B
Ruby
Raw Normal View History

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)
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)
@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