Class: Panache::Style
- Inherits:
-
Object
- Object
- Panache::Style
- Defined in:
- lib/panache.rb
Class Method Summary collapse
Instance Method Summary collapse
- #check(line) ⇒ Object
- #checks?(file_name) ⇒ Boolean
-
#initialize(file_regex) ⇒ Style
constructor
A new instance of Style.
- #rule(regex, message) ⇒ Object
- #spaces_per_tab(n) ⇒ Object
Constructor Details
#initialize(file_regex) ⇒ Style
Returns a new instance of Style.
38 39 40 41 42 |
# File 'lib/panache.rb', line 38 def initialize(file_regex) @tab_spaces = DEFAULT_TAB_SPACES @file_regex = file_regex @rules = [] end |
Class Method Details
Instance Method Details
#check(line) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/panache.rb', line 66 def check(line) # Replace tabs with spaces according to the specified conversion. line.gsub!("\t", " " * @tab_spaces) @rules.flat_map do |rule| violations = rule.check(line) violations.each { |v| v.style = self } end end |
#checks?(file_name) ⇒ Boolean
62 63 64 |
# File 'lib/panache.rb', line 62 def checks?(file_name) file_name =~ @file_regex end |
#rule(regex, message) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/panache.rb', line 54 def rule(regex, ) if regex.is_a? Array @rules << Rule.new(regex, ) else @rules << Rule.new([regex], ) end end |
#spaces_per_tab(n) ⇒ Object
50 51 52 |
# File 'lib/panache.rb', line 50 def spaces_per_tab(n) @tab_spaces = n end |