mirror of
https://github.com/hakanensari/frankfurter.git
synced 2024-11-24 20:15:15 +01:00
e5815737c1
- bumped gems - rm bots - rm pry byebug - added rubocop-shopify and corrected generated warnings
49 lines
923 B
Ruby
49 lines
923 B
Ruby
# frozen_string_literal: true
|
|
|
|
require "day"
|
|
require "bank/feed"
|
|
|
|
module Bank
|
|
class << self
|
|
def fetch_all!
|
|
data = Feed.historical.to_a
|
|
jsonify!(data)
|
|
Day.dataset.insert_conflict.multi_insert(data)
|
|
end
|
|
|
|
def fetch_ninety_days!
|
|
data = Feed.ninety_days.to_a
|
|
jsonify!(data)
|
|
Day.dataset.insert_conflict.multi_insert(data)
|
|
end
|
|
|
|
def fetch_current!
|
|
data = Feed.current.to_a
|
|
jsonify!(data)
|
|
Day.find_or_create(data.first)
|
|
end
|
|
|
|
def replace_all!
|
|
data = Feed.historical.to_a
|
|
jsonify!(data)
|
|
Day.dataset.delete
|
|
Day.multi_insert(data)
|
|
end
|
|
|
|
def seed_with_saved_data!
|
|
data = Feed.saved_data.to_a
|
|
jsonify!(data)
|
|
Day.dataset.delete
|
|
Day.multi_insert(data)
|
|
end
|
|
|
|
private
|
|
|
|
def jsonify!(data)
|
|
data.each do |day|
|
|
day[:rates] = Sequel.pg_jsonb(day[:rates])
|
|
end
|
|
end
|
|
end
|
|
end
|