Class: Filecop::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/filecop/rule.rb

Instance Method Summary collapse

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(options)
  @part = options['part']
  @type = options['type']
  @pattern = options['pattern']
  @caption = options['caption']
  @description = options['description']
end

Instance Method Details

#matches?(file) ⇒ Boolean

Returns:



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

#messageObject



27
28
29
30
31
# File 'lib/filecop/rule.rb', line 27

def message
  output = "#{@caption}."
  output += " #{@description}" if @description
  output
end