Class: Lutra::Formatter
- Inherits:
-
Object
- Object
- Lutra::Formatter
- Defined in:
- lib/lutra/formatter.rb
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#formatters ⇒ Object
readonly
Returns the value of attribute formatters.
Instance Method Summary collapse
- #add(name, short_name, class_name) ⇒ Object
- #display(notes) ⇒ Object
- #get(name) ⇒ Object
-
#initialize(options = {}) ⇒ Formatter
constructor
A new instance of Formatter.
- #set(name) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Formatter
Returns a new instance of Formatter.
5 6 7 8 9 10 11 |
# File 'lib/lutra/formatter.rb', line 5 def initialize( = {}) @options = .merge() @current = :default @formatters = [ { name: :default, short: :d, class: Lutra::Formatters::Default } ] end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
3 4 5 |
# File 'lib/lutra/formatter.rb', line 3 def current @current end |
#formatters ⇒ Object (readonly)
Returns the value of attribute formatters.
3 4 5 |
# File 'lib/lutra/formatter.rb', line 3 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 << { name: name, short: short_name, class: class_name } end end |
#display(notes) ⇒ Object
33 34 35 |
# File 'lib/lutra/formatter.rb', line 33 def display(notes) get(@current)[:class].new(@options).display(notes) end |
#get(name) ⇒ Object
13 14 15 16 17 |
# File 'lib/lutra/formatter.rb', line 13 def get(name) @formatters.select do |f| f[:name] == name || f[:short] == name end.first 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 |