Class: RateCenter::DataLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/rate_center/data_loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ DataLoader

Returns a new instance of DataLoader.



7
8
9
# File 'lib/rate_center/data_loader.rb', line 7

def initialize(**options)
  @data_directory = options.fetch(:data_directory) { Pathname(File.expand_path("../../data/", __dir__)) }
end

Instance Attribute Details

#citiesObject (readonly)

Returns the value of attribute cities.



5
6
7
# File 'lib/rate_center/data_loader.rb', line 5

def cities
  @cities
end

#data_directoryObject (readonly)

Returns the value of attribute data_directory.



5
6
7
# File 'lib/rate_center/data_loader.rb', line 5

def data_directory
  @data_directory
end

#lataObject (readonly)

Returns the value of attribute lata.



5
6
7
# File 'lib/rate_center/data_loader.rb', line 5

def lata
  @lata
end

#rate_centersObject (readonly)

Returns the value of attribute rate_centers.



5
6
7
# File 'lib/rate_center/data_loader.rb', line 5

def rate_centers
  @rate_centers
end

Instance Method Details

#load(type) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rate_center/data_loader.rb', line 11

def load(type, ...)
  case type.to_sym
  when :all
    @cities = load_data("cities", :all)
    @rate_centers = load_data("rate_centers", :all)
  when :cities
    @cities = load_data("cities", ...)
  when :rate_centers
    @rate_centers = load_data("rate_centers", ...)
  when :lata
    @lata = load_data("lata", ...)
  else
    raise ArgumentError, "Invalid type: #{type}"
  end

  nil
end