Class: RVGP::Journal::Pricer::Price

Inherits:
Base::Reader show all
Defined in:
lib/rvgp/journal/pricer.rb

Overview

This class represents a line, parsed from a prices journal. And, an instance of this class represents an exchange rate. This class contains a datetime, an amount, and two codes.

Instance Attribute Summary collapse

Attributes inherited from Base::Reader

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base::Reader

readers

Instance Attribute Details

#amountRVGP::Journal::Commodity (readonly)

The ratio of lcode, to rcode. Aka: The exchange rate.

Returns:



33
34
35
# File 'lib/rvgp/journal/pricer.rb', line 33

def amount
  @amount
end

#atTime (readonly)

The time at which this exchange rate was declared in effect

Returns:

  • (Time)

    the current value of at



33
34
35
# File 'lib/rvgp/journal/pricer.rb', line 33

def at
  @at
end

#lcodeString (readonly)

The character alphabetic code, or symbol for the left side of the exchange pair

Returns:

  • (String)

    the current value of lcode



33
34
35
# File 'lib/rvgp/journal/pricer.rb', line 33

def lcode
  @lcode
end

#rcodeString (readonly)

The character alphabetic code, or symbol for the right side of the exchange pair. This code should (always?) match the amount.code

Returns:

  • (String)

    the current value of rcode



33
34
35
# File 'lib/rvgp/journal/pricer.rb', line 33

def rcode
  @rcode
end

Class Method Details

.to_key(code1, code2) ⇒ String

Create a string, for this pair, that is unique to the codes, regardless of the order in which they’re provided. This enables us to assert bidirectionality in the lookup of prices.

Parameters:

  • code1 (String)

    A three character alphabetic currency code

  • code2 (String)

    A three character alphabetic currency code

Returns:

  • (String)

    A code, intended for use in Hash table lookups



47
48
49
# File 'lib/rvgp/journal/pricer.rb', line 47

def self.to_key(code1, code2)
  [code1, code2].sort.join(' ')
end

Instance Method Details

#to_keyString

A shortcut, to to_key, if a caller is looking to use this price in a Hash

Returns:

  • (String)

    A code, intended for use in Hash table lookups



38
39
40
# File 'lib/rvgp/journal/pricer.rb', line 38

def to_key
  self.class.to_key lcode, rcode
end