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.
10 11 12 13 |
# File 'lib/trade-o-matic/structs/currency_pair.rb', line 10 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
5 6 7 8 |
# File 'lib/trade-o-matic/structs/currency_pair.rb', line 5 def self.for_code(_pair, _quote=nil) return _pair if _pair.is_a? self self.new _pair, _quote end |
Instance Method Details
#==(_other) ⇒ Object
15 16 17 18 |
# File 'lib/trade-o-matic/structs/currency_pair.rb', line 15 def ==(_other) return false unless _other.is_a? CurrencyPair base == _other.base and quote == _other.quote end |
#compatible_with?(_pair, _quote = nil) ⇒ Boolean
25 26 27 28 |
# File 'lib/trade-o-matic/structs/currency_pair.rb', line 25 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
20 21 22 23 |
# File 'lib/trade-o-matic/structs/currency_pair.rb', line 20 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
30 31 32 |
# File 'lib/trade-o-matic/structs/currency_pair.rb', line 30 def to_s "#{base}/#{quote}" end |