Class: Trader::SyncConverter
- Inherits:
-
FixedConverter
- Object
- Converter
- FixedConverter
- Trader::SyncConverter
- Defined in:
- lib/trade-o-matic/converters/sync_converter.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#ttl ⇒ Object
readonly
Returns the value of attribute ttl.
Instance Method Summary collapse
- #expired? ⇒ Boolean
-
#initialize(_ttl, &_block) ⇒ SyncConverter
constructor
A new instance of SyncConverter.
- #rate ⇒ Object
Methods inherited from FixedConverter
Methods inherited from Converter
Constructor Details
#initialize(_ttl, &_block) ⇒ SyncConverter
Returns a new instance of SyncConverter.
5 6 7 8 9 |
# File 'lib/trade-o-matic/converters/sync_converter.rb', line 5 def initialize(_ttl, &_block) super nil @ttl = _ttl @block = _block end |
Instance Attribute Details
#ttl ⇒ Object (readonly)
Returns the value of attribute ttl.
3 4 5 |
# File 'lib/trade-o-matic/converters/sync_converter.rb', line 3 def ttl @ttl end |
Instance Method Details
#expired? ⇒ Boolean
11 12 13 |
# File 'lib/trade-o-matic/converters/sync_converter.rb', line 11 def expired? @rate.nil? || @last_sync < (Time.now - @ttl) end |
#rate ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/trade-o-matic/converters/sync_converter.rb', line 15 def rate if expired? @rate = @block.call @last_sync = Time.now end @rate end |