Class: Trenni::Formatters::Formatter
- Inherits:
-
Object
- Object
- Trenni::Formatters::Formatter
- Defined in:
- lib/trenni/formatters/formatter.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #for(klass, &block) ⇒ Object
- #format(object, options = {}) ⇒ Object (also: #text)
-
#initialize(options = {}) ⇒ Formatter
constructor
A new instance of Formatter.
Constructor Details
#initialize(options = {}) ⇒ Formatter
Returns a new instance of Formatter.
26 27 28 29 |
# File 'lib/trenni/formatters/formatter.rb', line 26 def initialize( = {}) @options = @formatters = {} end |
Instance Method Details
#[](key) ⇒ Object
45 46 47 |
# File 'lib/trenni/formatters/formatter.rb', line 45 def [] key @options[key] end |
#for(klass, &block) ⇒ Object
49 50 51 |
# File 'lib/trenni/formatters/formatter.rb', line 49 def for(klass, &block) @formatters[klass] = block end |
#format(object, options = {}) ⇒ Object Also known as: text
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/trenni/formatters/formatter.rb', line 31 def format(object, = {}) if formatter = @formatters[object.class] @formatters[object.class].call(object, ) else if object Strings::to_html(object.to_s) else [:blank] || "" end end end |