Class: Utxoracle::BatchOracle
- Inherits:
-
Object
- Object
- Utxoracle::BatchOracle
- Defined in:
- lib/utxoracle/batch_oracle.rb
Instance Method Summary collapse
-
#initialize(provider, log = false) ⇒ BatchOracle
constructor
A new instance of BatchOracle.
- #prices(start_date, end_date) ⇒ Object
Constructor Details
#initialize(provider, log = false) ⇒ BatchOracle
Returns a new instance of BatchOracle.
5 6 7 8 |
# File 'lib/utxoracle/batch_oracle.rb', line 5 def initialize(provider, log = false) @provider = provider @log = log end |
Instance Method Details
#prices(start_date, end_date) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/utxoracle/batch_oracle.rb', line 10 def prices(start_date, end_date) formatted_start_date = Time.parse start_date.tr('\n', '') formatted_end_date = Time.parse end_date.tr('\n', '') ret = {} date = formatted_start_date threads = [] while date < formatted_end_date # Bind `date` to thread scope: https://ruby-doc.org/core-2.0.0/Thread.html#method-c-new threads << Thread.new(date) do |t_date| oracle = Utxoracle::Oracle.new(@provider, log = @log) date_str = t_date.to_s[0..9] ret[date_str] = oracle.price(date_str) end date += Utxoracle::Oracle::SECONDS_PER_DAY end threads.each(&:join) puts ret ret end |