2017-12-31 17:44:08 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'currency'
|
2018-03-08 02:05:19 +01:00
|
|
|
require 'bank/feed'
|
2017-12-31 17:44:08 +01:00
|
|
|
|
|
|
|
module Bank
|
2018-06-06 17:30:18 +02:00
|
|
|
def self.fetch_all!
|
2018-03-22 09:49:32 +01:00
|
|
|
Currency.dataset.insert_conflict.multi_insert(Feed.historical.to_a)
|
2017-12-31 17:44:08 +01:00
|
|
|
end
|
|
|
|
|
2018-06-06 17:30:18 +02:00
|
|
|
def self.fetch_ninety_days!
|
|
|
|
Currency.dataset.insert_conflict.multi_insert(Feed.ninety_days.to_a)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.fetch_current!
|
2017-12-31 17:44:08 +01:00
|
|
|
Currency.db.transaction do
|
2018-03-08 02:05:19 +01:00
|
|
|
Feed.current.each do |hsh|
|
2017-12-31 17:44:08 +01:00
|
|
|
Currency.find_or_create(hsh)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-03-22 09:49:32 +01:00
|
|
|
|
2018-06-06 17:30:18 +02:00
|
|
|
def self.replace_all!
|
2018-03-22 09:49:32 +01:00
|
|
|
Currency.dataset.delete
|
|
|
|
Currency.multi_insert(Feed.historical.to_a)
|
|
|
|
end
|
2017-12-31 17:44:08 +01:00
|
|
|
end
|