Class: File::Visitor::Filter::Ext
- Inherits:
-
Object
- Object
- File::Visitor::Filter::Ext
- Defined in:
- lib/file/visitor/filter/ext.rb
Instance Method Summary collapse
-
#initialize(ext) ⇒ Ext
constructor
A new instance of Ext.
- #match?(path) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(ext) ⇒ Ext
Returns a new instance of Ext.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/file/visitor/filter/ext.rb', line 6 def initialize(ext) if ext.is_a?(Array) @extentions = ext elsif ext.nil? raise ArgumentError, "ext is nil" else @extentions = [ext] end @extentions = @extentions.map do |extention| if extention.nil? || !(extention.is_a?(String) || extention.is_a?(Symbol)) raise ArgumentError, "ext must be Sting/Symbol." end extention = extention.to_s unless extention =~ /\A\./ extention = ".#{extention}" end extention end end |
Instance Method Details
#match?(path) ⇒ Boolean
29 30 31 32 |
# File 'lib/file/visitor/filter/ext.rb', line 29 def match?(path) ext = File.extname(path) @extentions.any? { |fext| ext == fext } end |
#to_s ⇒ Object
34 35 36 |
# File 'lib/file/visitor/filter/ext.rb', line 34 def to_s "%s[%s]" % [self.class.name, @extentions.join(',')] end |