Class: Exrt::Cli::Format

Inherits:
Object
  • Object
show all
Defined in:
lib/exrt/cli/format.rb

Class Method Summary collapse

Class Method Details

.history(response) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/exrt/cli/format.rb', line 17

def self.history(response)
  r = self.to_json(response)
  rows = []
  r['rates'].each do |date, rates|
    row = [date]
    rates.each do |symbol, rate|
      row.prepend(symbol, rate)
    end

    rows.append(row)
  end

  rows
end

.latest(response) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/exrt/cli/format.rb', line 7

def self.latest(response)
  r = self.to_json(response)
  rows = []
  r['rates'].each do |symbol, value|
    rows.append([symbol, value])
  end

  rows
end

.to_json(resp) ⇒ Object



32
33
34
# File 'lib/exrt/cli/format.rb', line 32

def self.to_json(resp)
  JSON.parse(resp)
end