Class: Asuka::LineFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/asuka/line_formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(formatter, *steps) ⇒ LineFormatter

Returns a new instance of LineFormatter.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/asuka/line_formatter.rb', line 5

def initialize(formatter, *steps)
  steps = steps.flatten

  if steps.empty? && formatter.respond_to?(:default_steps)
    @steps = formatter.default_steps
  else
    @steps = steps
  end

  @formatter = formatter
end

Instance Attribute Details

#formatterObject

Returns the value of attribute formatter.



3
4
5
# File 'lib/asuka/line_formatter.rb', line 3

def formatter
  @formatter
end

#stepsObject

Returns the value of attribute steps.



3
4
5
# File 'lib/asuka/line_formatter.rb', line 3

def steps
  @steps
end

Instance Method Details

#format(line) ⇒ Object



17
18
19
# File 'lib/asuka/line_formatter.rb', line 17

def format(line)
  steps.inject(line) { |line, step| formatter.send(step, line) }
end