class RailwayJp::Station

Constants

MAPPINGS

Public Class Methods

all() click to toggle source
# File lib/railway_jp/station.rb, line 17
def all
  @all ||= data.map { |row| new(row) }
end
find(id) click to toggle source
# File lib/railway_jp/station.rb, line 21
def find(id)
  row = data_index_by_id[id.to_s]
  row ? new(row) : nil
end
new(row) click to toggle source
# File lib/railway_jp/station.rb, line 41
def initialize(row)
  MAPPINGS.each do |attr, column_name|
    instance_variable_set("@#{attr}", row[column_name])
  end
end

Private Class Methods

data() click to toggle source

@return [CSV::Table]

# File lib/railway_jp/station.rb, line 29
def data
  @data ||= CSV.parse(File.open(File.join(__dir__, '../data','station.csv')), headers: true)
end
data_index_by_id() click to toggle source
# File lib/railway_jp/station.rb, line 33
def data_index_by_id
  @data_index_by_id ||= data.each_with_object({}) { |cur, obj| obj[cur['station_cd']] = cur }
end

Public Instance Methods

line() click to toggle source
# File lib/railway_jp/station.rb, line 47
def line
  @line ||= Line.find(line_id)
end
line_name() click to toggle source
# File lib/railway_jp/station.rb, line 51
def line_name
  line&.name
end