Class: 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
Constructor Details
#initialize(_ttl, &_block) ⇒ SyncConverter
Returns a new instance of SyncConverter.
5 6 7 8 |
# File 'lib/trade-o-matic/converters/sync_converter.rb', line 5 def initialize(_ttl, &_block) @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
10 11 12 |
# File 'lib/trade-o-matic/converters/sync_converter.rb', line 10 def expired? @last_sync < Time.new - @ttl end |
#rate ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/trade-o-matic/converters/sync_converter.rb', line 14 def rate if @last_sync.nil? or expired? @rate = @block.call @last_sync = Time.now end @rate end |