Class: Lutra::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/lutra/formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Formatter

Returns a new instance of Formatter.



7
8
9
10
11
# File 'lib/lutra/formatter.rb', line 7

def initialize(options = {})
  @options = options
  @current = :default
  @formatters = [default_formatter]
end

Instance Attribute Details

#currentObject (readonly)

Returns the value of attribute current.



5
6
7
# File 'lib/lutra/formatter.rb', line 5

def current
  @current
end

#formattersObject (readonly)

Returns the value of attribute formatters.



5
6
7
# File 'lib/lutra/formatter.rb', line 5

def formatters
  @formatters
end

Instance Method Details

#add(name, short_name, class_name) ⇒ Object



27
28
29
30
31
# File 'lib/lutra/formatter.rb', line 27

def add(name, short_name, class_name)
  if formatter?(class_name)
    @formatters << FormatterEntry.new(name, short_name, class_name)
  end
end

#display(notes) ⇒ Object



33
34
35
# File 'lib/lutra/formatter.rb', line 33

def display(notes)
  get(@current).class_name.new(@options).display(notes)
end

#get(name) ⇒ Object



13
14
15
16
17
# File 'lib/lutra/formatter.rb', line 13

def get(name)
  @formatters.find do |f|
    f.name == name || f.short == name
  end
end

#set(name) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/lutra/formatter.rb', line 19

def set(name)
  if get(name)
    @current = name
  else
    raise FormatterNotFound
  end
end