Class: RailwayJp::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/railway_jp/line.rb

Constant Summary collapse

MAPPINGS =
{
  id: 'line_cd',
  name: 'line_name',
  color: 'line_color_c',
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row) ⇒ Line

Returns a new instance of Line.



34
35
36
37
38
# 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

Class Method Details

.allObject



10
11
12
# File 'lib/railway_jp/line.rb', line 10

def all
  @all ||= data.map { |row| new(row) }
end

.find(id) ⇒ Object



14
15
16
17
# File 'lib/railway_jp/line.rb', line 14

def find(id)
  row = data_index_by_id[id.to_s]
  row ? new(row) : nil
end