Class: Filecop::Rule
- Inherits:
-
Object
- Object
- Filecop::Rule
- Defined in:
- lib/filecop/rule.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ Rule
constructor
A new instance of Rule.
- #matches?(file) ⇒ Boolean
- #message ⇒ Object
Constructor Details
#initialize(options) ⇒ Rule
Returns a new instance of Rule.
3 4 5 6 7 8 9 |
# File 'lib/filecop/rule.rb', line 3 def initialize() @part = ['part'] @type = ['type'] @pattern = ['pattern'] @caption = ['caption'] @description = ['description'] end |
Instance Method Details
#matches?(file) ⇒ Boolean
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/filecop/rule.rb', line 11 def matches?(file) parts = { path: file, filename: Pathname.new(file).basename, extension: File.extname(file).delete('.') } to_check = parts[@part.to_sym].to_s if @type == 'regex' reg = Regexp.new(@pattern, true) reg.match(to_check) else to_check == @pattern end end |
#message ⇒ Object
27 28 29 30 31 |
# File 'lib/filecop/rule.rb', line 27 def output = "#{@caption}." output += " #{@description}" if @description output end |