Class: Currency::Formatter::Template
- Defined in:
- lib/currency/formatter.rb
Overview
The underlying object for Currency::Formatter#format. This object is cloned and initialized with strings created from Formatter#format. It handles the Formatter#format string interpolation.
Constant Summary collapse
- @@empty_hash =
{ }
Instance Attribute Summary collapse
-
#code ⇒ Object
The currency code or nil.
-
#currency ⇒ Object
The Currency::Currency object being formatted.
-
#fraction ⇒ Object
The fraction part of the value, with decimal_separator or nil.
-
#money ⇒ Object
The Currency::Money object being formatted.
-
#sign ⇒ Object
The sign: ‘-’ or nil.
-
#symbol ⇒ Object
The currency symbol or nil.
-
#template ⇒ Object
The template string.
-
#time ⇒ Object
The time or nil.
-
#whole ⇒ Object
The whole part of the value, with thousands_separator or nil.
Instance Method Summary collapse
-
#format ⇒ Object
Formats the current state using the template.
-
#initialize(opts = @@empty_hash) ⇒ Template
constructor
A new instance of Template.
-
#template_proc(template = @template) ⇒ Object
Defines a the self._format template procedure using the template as a string to be interpolated.
Constructor Details
#initialize(opts = @@empty_hash) ⇒ Template
Returns a new instance of Template.
40 41 42 43 44 45 46 |
# File 'lib/currency/formatter.rb', line 40 def initialize(opts = @@empty_hash) @template = @template_proc = nil opts.each_pair{ | k, v | self.send("#{k}=", v) } end |
Instance Attribute Details
#code ⇒ Object
The currency code or nil.
35 36 37 |
# File 'lib/currency/formatter.rb', line 35 def code @code end |
#currency ⇒ Object
The Currency::Currency object being formatted.
24 25 26 |
# File 'lib/currency/formatter.rb', line 24 def currency @currency end |
#fraction ⇒ Object
The fraction part of the value, with decimal_separator or nil.
31 32 33 |
# File 'lib/currency/formatter.rb', line 31 def fraction @fraction end |
#money ⇒ Object
The Currency::Money object being formatted.
22 23 24 |
# File 'lib/currency/formatter.rb', line 22 def money @money end |
#sign ⇒ Object
The sign: ‘-’ or nil.
27 28 29 |
# File 'lib/currency/formatter.rb', line 27 def sign @sign end |
#symbol ⇒ Object
The currency symbol or nil.
33 34 35 |
# File 'lib/currency/formatter.rb', line 33 def symbol @symbol end |
#template ⇒ Object
The template string.
19 20 21 |
# File 'lib/currency/formatter.rb', line 19 def template @template end |
#time ⇒ Object
The time or nil.
38 39 40 |
# File 'lib/currency/formatter.rb', line 38 def time @time end |
#whole ⇒ Object
The whole part of the value, with thousands_separator or nil.
29 30 31 |
# File 'lib/currency/formatter.rb', line 29 def whole @whole end |
Instance Method Details
#format ⇒ Object
Formats the current state using the template.
71 72 73 74 |
# File 'lib/currency/formatter.rb', line 71 def format template_proc _format end |
#template_proc(template = @template) ⇒ Object
Defines a the self._format template procedure using the template as a string to be interpolated.
60 61 62 63 64 65 66 67 |
# File 'lib/currency/formatter.rb', line 60 def template_proc(template = @template) return @template_proc if @template_proc @template_proc = template || '' # @template_proc = @template_proc.gsub(/[\\"']/) { | x | "\\" + x } @template_proc = "def self._format; \"#{@template_proc}\"; end" self.instance_eval @template_proc @template_proc end |