Class: File::Visitor::Filter::Ext

Inherits:
Object
  • Object
show all
Defined in:
lib/file/visitor/filter/ext.rb

Instance Method Summary collapse

Constructor Details

#initialize(extstr) ⇒ Ext

Returns a new instance of Ext.



6
7
8
9
10
11
12
13
14
15
# File 'lib/file/visitor/filter/ext.rb', line 6

def initialize(extstr)
  if extstr.nil? || !(extstr.is_a?(String) || extstr.is_a?(Symbol))
    raise ArgumentError, "ext must be Sting/Symbol"
  end
  extstr = extstr.to_s
  unless extstr =~ /\A\./
    extstr = ".#{extstr}"
  end
  @ext = extstr
end

Instance Method Details

#match?(path) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
# File 'lib/file/visitor/filter/ext.rb', line 17

def match?(path)
  ext = File.extname(path)
  ext == @ext
end

#to_sObject



22
23
24
# File 'lib/file/visitor/filter/ext.rb', line 22

def to_s
  "%s[%s]" % [self.class.name, @ext.to_s]
end