Class: File::Visitor::Filter::Name

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

Instance Method Summary collapse

Constructor Details

#initialize(exp) ⇒ Name

Returns a new instance of Name.



6
7
8
9
10
11
# File 'lib/file/visitor/filter/name.rb', line 6

def initialize(exp)
  unless exp.is_a?(String) || exp.is_a?(Regexp)
    raise ArgumentError, "expression must be String or Regexp"
  end
  @exp = exp
end

Instance Method Details

#match?(path) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (RuntimeError)


13
14
15
16
17
18
# File 'lib/file/visitor/filter/name.rb', line 13

def match?(path)
  filename = File.basename(path)
  return @exp == filename if @exp.is_a?(String)
  return filename =~ @exp if @exp.is_a?(Regexp)
  raise RuntimeError, "unexpected exp type: #{@exp.class}"
end

#to_sObject



20
21
22
# File 'lib/file/visitor/filter/name.rb', line 20

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