Class: Gera::CurrencyRatesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/gera/currency_rates_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/gera/currency_rates_controller.rb', line 12

def index
  if snapshot.present?
    render locals: {
      rates: snapshot.rates,
      created_at: snapshot.created_at
    }
  else
    render :page, locals: { message: 'No current currency rate snapshot found' }
  end
end

#modesObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/gera/currency_rates_controller.rb', line 30

def modes
  body = CSV.generate do |csv|
    line = ['income\outcome']
    line += Money::Currency.all.map(&:to_s)
    csv << line
    Money::Currency.all.each do |cur_from|
      line = [cur_from]
      Money::Currency.all.each do |cur_to|
        rate = snapshot.rates.find_by(cur_from: cur_from.iso_code, cur_to: cur_to.iso_code)
        d = CurrencyRateDecorator.decorate rate
        line << d.mode
      end
      csv << line
    end
  end

  respond_to do |format|
    format.html { raise 'CSV only supported' }
    format.csv { send_data body, filename: "exchange_rates-modes-#{Date.today}.csv" }
  end
end

#showObject



23
24
25
26
27
28
# File 'app/controllers/gera/currency_rates_controller.rb', line 23

def show
  render locals: {
    currency_rate: currency_rate,
    currency_pair: currency_rate.currency_pair
  }
end