Module: Export

Defined in:
lib/ctfc/export.rb

Overview

Keep methods to export data as csv or json. JSON extract all data, while CSV only prices.

Class Method Summary collapse

Class Method Details

.to_csv(source, response = {}) ⇒ Object

Save crypto prices in csv table.



13
14
15
16
17
18
19
# File 'lib/ctfc/export.rb', line 13

def to_csv(source, response = {})
  table = "ctfc_#{response[:fiat]}_#{source}.csv"
  coins = response[:coins]
  data_row = price_array_from response
  create_csv_headers(table, coins) unless File.exist?(table)
  CSV.open(table, 'ab') { |column| column << data_row }
end

.to_json(source, response = {}) ⇒ Object

Extract all data in json file.



23
24
25
26
27
28
# File 'lib/ctfc/export.rb', line 23

def to_json(source, response = {})
  table = "ctfc_#{response[:fiat]}_#{source}.json"
  File.open(table, 'ab') do |append|
    append.puts JSON.pretty_generate response
  end
end