Class: Forex::CurrencyCode
- Inherits:
-
Object
- Object
- Forex::CurrencyCode
- Defined in:
- lib/forex/tabular_rates.rb
Instance Method Summary collapse
-
#initialize(string) ⇒ CurrencyCode
constructor
A new instance of CurrencyCode.
- #invalid? ⇒ Boolean
- #to_s ⇒ Object
-
#valid? ⇒ Boolean
TODO validate the currency codes via www.xe.com/iso4217.php.
Constructor Details
#initialize(string) ⇒ CurrencyCode
Returns a new instance of CurrencyCode.
54 55 56 |
# File 'lib/forex/tabular_rates.rb', line 54 def initialize(string) @string = string end |
Instance Method Details
#invalid? ⇒ Boolean
64 65 66 |
# File 'lib/forex/tabular_rates.rb', line 64 def invalid? !valid? end |
#to_s ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/forex/tabular_rates.rb', line 68 def to_s @string.strip. # Replace currency symbols with letter equivalent # TODO go crazy and add the rest http://www.xe.com/symbols.php gsub('$', 'D'). # Remove all non word charactes ([^A-Za-z0-9_]) gsub(/\W/,'') end |
#valid? ⇒ Boolean
TODO validate the currency codes via www.xe.com/iso4217.php
59 60 61 62 |
# File 'lib/forex/tabular_rates.rb', line 59 def valid? @string = to_s # hack !@string.blank? && @string.length == 3 end |