Class: Trader::CurrencyPair
- Inherits:
-
Object
- Object
- Trader::CurrencyPair
- Defined in:
- lib/trade-o-matic/structs/currency_pair.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#quote ⇒ Object
readonly
Returns the value of attribute quote.
Class Method Summary collapse
Instance Method Summary collapse
- #==(_other) ⇒ Object
- #compatible_with?(_pair, _quote = nil) ⇒ Boolean
- #convertible_to?(_pair, _quote = nil) ⇒ Boolean
-
#initialize(_base, _quote) ⇒ CurrencyPair
constructor
A new instance of CurrencyPair.
- #to_s ⇒ Object
Constructor Details
#initialize(_base, _quote) ⇒ CurrencyPair
Returns a new instance of CurrencyPair.
14 15 16 17 |
# File 'lib/trade-o-matic/structs/currency_pair.rb', line 14 def initialize(_base, _quote) @base = Currency.for_code _base @quote = Currency.for_code _quote end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
3 4 5 |
# File 'lib/trade-o-matic/structs/currency_pair.rb', line 3 def base @base end |
#quote ⇒ Object (readonly)
Returns the value of attribute quote.
3 4 5 |
# File 'lib/trade-o-matic/structs/currency_pair.rb', line 3 def quote @quote end |
Class Method Details
.for_code(_pair, _quote = nil) ⇒ Object
9 10 11 12 |
# File 'lib/trade-o-matic/structs/currency_pair.rb', line 9 def self.for_code(_pair, _quote=nil) return _pair if _pair.is_a? self self.new _pair, _quote end |
.parse(_string) ⇒ Object
5 6 7 |
# File 'lib/trade-o-matic/structs/currency_pair.rb', line 5 def self.parse(_string) new *(_string.split '/') end |
Instance Method Details
#==(_other) ⇒ Object
19 20 21 22 |
# File 'lib/trade-o-matic/structs/currency_pair.rb', line 19 def ==(_other) return false unless _other.is_a? CurrencyPair base == _other.base and quote == _other.quote end |
#compatible_with?(_pair, _quote = nil) ⇒ Boolean
29 30 31 32 |
# File 'lib/trade-o-matic/structs/currency_pair.rb', line 29 def compatible_with?(_pair, _quote=nil) _pair = for_code _pair, _quote base.compatible_with?(_pair.base) and quote.compatible_with?(_pair.quote) end |
#convertible_to?(_pair, _quote = nil) ⇒ Boolean
24 25 26 27 |
# File 'lib/trade-o-matic/structs/currency_pair.rb', line 24 def convertible_to?(_pair, _quote=nil) _pair = for_code _pair, _quote base.convertible_to?(_pair.base) and quote.convertible_to?(_pair.quote) end |
#to_s ⇒ Object
34 35 36 |
# File 'lib/trade-o-matic/structs/currency_pair.rb', line 34 def to_s "#{base}/#{quote}" end |