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.
7 8 9 10 11 |
# File 'lib/lutra/formatter.rb', line 7 def initialize( = {}) = @current = :default @formatters = [default_formatter] end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
5 6 7 |
# File 'lib/lutra/formatter.rb', line 5 def current @current end |
#formatters ⇒ Object (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().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 |