Class: RailwayJp::Line

Inherits:
Object
  • Object
show all
Includes:
Equality
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

Methods included from Equality

#==, #eql?, #hash

Constructor Details

#initialize(row) ⇒ Line

Returns a new instance of Line.



38
39
40
41
42
# File 'lib/railway_jp/line.rb', line 38

def initialize(row)
  MAPPINGS.each do |attr, column_name|
    instance_variable_set("@#{attr}", row[column_name])
  end
end

Class Method Details

.allObject



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

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

.find(id) ⇒ Object



18
19
20
21
# File 'lib/railway_jp/line.rb', line 18

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