Class: CurrencyInWords::Texterizer
- Inherits:
-
Object
- Object
- CurrencyInWords::Texterizer
- Defined in:
- lib/currency-in-words.rb
Overview
:nodoc: all This is the context class for texterizers
Instance Attribute Summary collapse
-
#number_parts ⇒ Object
readonly
Returns the value of attribute number_parts.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#texterizer ⇒ Object
readonly
Returns the value of attribute texterizer.
Instance Method Summary collapse
-
#initialize(texterizer, splitted_number, options = {}) ⇒ Texterizer
constructor
A new instance of Texterizer.
- #texterize ⇒ Object
Constructor Details
#initialize(texterizer, splitted_number, options = {}) ⇒ Texterizer
Returns a new instance of Texterizer.
108 109 110 111 112 |
# File 'lib/currency-in-words.rb', line 108 def initialize texterizer, splitted_number, = {} @texterizer = texterizer @number_parts = splitted_number @options = end |
Instance Attribute Details
#number_parts ⇒ Object (readonly)
Returns the value of attribute number_parts.
106 107 108 |
# File 'lib/currency-in-words.rb', line 106 def number_parts @number_parts end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
106 107 108 |
# File 'lib/currency-in-words.rb', line 106 def @options end |
#texterizer ⇒ Object (readonly)
Returns the value of attribute texterizer.
106 107 108 |
# File 'lib/currency-in-words.rb', line 106 def texterizer @texterizer end |
Instance Method Details
#texterize ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/currency-in-words.rb', line 114 def texterize if @texterizer.respond_to?('texterize') texterized_number = @texterizer.texterize self if texterized_number.is_a?(String) return texterized_number else raise TypeError, "a texterizer must return a String" if @options[:raise] end else raise NoMethodError, "a texterizer must provide a 'texterize' method" if @options[:raise] end # Fallback on EnTexterizer unless @texterizer.instance_of?(EnTexterizer) @texterizer = EnTexterizer.new self.texterize else raise RuntimeError, "you should use the option ':raise => true' to see what goes wrong" end end |