class RailwayJp::Line
Constants
- MAPPINGS
Public Class Methods
all()
click to toggle source
# File lib/railway_jp/line.rb, line 10 def all @all ||= data.map { |row| new(row) } end
find(id)
click to toggle source
# File lib/railway_jp/line.rb, line 14 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/line.rb, line 34 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/line.rb, line 22 def data @data ||= CSV.parse(File.open(File.join(__dir__, '../data','line.csv')), headers: true) end
data_index_by_id()
click to toggle source
# File lib/railway_jp/line.rb, line 26 def data_index_by_id @data_index_by_id ||= data.each_with_object({}) { |cur, obj| obj[cur['line_cd']] = cur } end