Class: Yay::Autoformatter

Inherits:
Object
  • Object
show all
Defined in:
lib/yay/autoformatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAutoformatter

Returns a new instance of Autoformatter.



9
10
11
12
13
14
15
16
# File 'lib/yay/autoformatter.rb', line 9

def initialize
  @wheel = [
    [Yay::ColourWheel::FG[:red],   Yay::ColourWheel::MISC[:bold]],
    [Yay::ColourWheel::FG[:green], Yay::ColourWheel::MISC[:bold]],
    [Yay::ColourWheel::FG[:blue],  Yay::ColourWheel::MISC[:bold]],
  ]
  @index = 0
end

Instance Attribute Details

#wheelObject (readonly)

the colour wheel can be retrieved for unit testing, etc



7
8
9
# File 'lib/yay/autoformatter.rb', line 7

def wheel
  @wheel
end

Instance Method Details

#get_rules(strings) ⇒ Object

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/yay/autoformatter.rb', line 18

def get_rules strings
  raise ArgumentError, "Cannot be an empty array" unless 
    strings.class == Array and strings.length > 0
  ruleset = Yay::RuleSet.new
  strings.each { |string| 
    colour = @wheel[@index % @wheel.length]
    ruleset.add_match [string], colour, false
    # iterate the index
    @index += 1
  }
  return ruleset.get_rules
end