Class: ExchangeRatesNBP::Clients::TableList

Inherits:
Object
  • Object
show all
Defined in:
lib/exchange_rates_nbp/clients/table_list.rb

Constant Summary collapse

PATTERN =
/[abch][0-9]{3}z[0-9]{6}/

Instance Method Summary collapse

Constructor Details

#initialize(year, table_type) ⇒ TableList

Returns a new instance of TableList.



6
7
8
9
10
11
# File 'lib/exchange_rates_nbp/clients/table_list.rb', line 6

def initialize(year, table_type)
  @year = year
  @table_type = table_type

  validate_year
end

Instance Method Details

#fetch_closest_to(date) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/exchange_rates_nbp/clients/table_list.rb', line 13

def fetch_closest_to(date)
  loop do
    table_id = table_id_for(date)
    return table_id unless table_id.nil?
    date -= 1
    return fetch_data_for_previous_year if date.year != @year
  end
end