Class: CurrencyUpdater::Currency
- Inherits:
-
Object
- Object
- CurrencyUpdater::Currency
- Defined in:
- lib/currency_updater/currency.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#rate ⇒ Object
Returns the value of attribute rate.
Instance Method Summary collapse
-
#initialize(currency) ⇒ Currency
constructor
A new instance of Currency.
- #name ⇒ Object
- #to_json ⇒ Object
- #to_xml ⇒ Object
Constructor Details
#initialize(currency) ⇒ Currency
Returns a new instance of Currency.
7 8 9 10 11 12 |
# File 'lib/currency_updater/currency.rb', line 7 def initialize(currency) raise "Need a 3LC for currency #{currency}" unless currency.length == 3 @currency = currency @code = currency.upcase @rate = 1.0 end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
6 7 8 |
# File 'lib/currency_updater/currency.rb', line 6 def code @code end |
#currency ⇒ Object
Returns the value of attribute currency.
5 6 7 |
# File 'lib/currency_updater/currency.rb', line 5 def currency @currency end |
#rate ⇒ Object
Returns the value of attribute rate.
4 5 6 |
# File 'lib/currency_updater/currency.rb', line 4 def rate @rate end |
Instance Method Details
#name ⇒ Object
14 15 16 |
# File 'lib/currency_updater/currency.rb', line 14 def name ::I18n.t("currency.#{@currency}") end |
#to_json ⇒ Object
18 19 20 21 22 |
# File 'lib/currency_updater/currency.rb', line 18 def to_json { :rate => rate, :code => code, :currency => currency }.to_json end |
#to_xml ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/currency_updater/currency.rb', line 24 def to_xml xml = Builder::XmlMarkup.new(:indent => 2) xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" xml.currency(:name => currency) do xml.code(code) xml.rate(rate) end xml.target! end |