Class: SgMRT::Line

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code = nil) ⇒ Line

Returns a new instance of Line.



82
83
84
85
# File 'lib/sg_mrt.rb', line 82

def initialize(code = nil)
  @code = code 
  @stations = []
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



80
81
82
# File 'lib/sg_mrt.rb', line 80

def code
  @code
end

#nameObject

Returns the value of attribute name.



80
81
82
# File 'lib/sg_mrt.rb', line 80

def name
  @name
end

#stationsObject

Returns the value of attribute stations.



80
81
82
# File 'lib/sg_mrt.rb', line 80

def stations
  @stations
end

Class Method Details

.allObject



102
103
104
# File 'lib/sg_mrt.rb', line 102

def all
  SgMRT.lines
end

.find_by_code(code) ⇒ Object



106
107
108
# File 'lib/sg_mrt.rb', line 106

def find_by_code(code)
  all.find{ |x| x.code == code}
end

Instance Method Details

#to_jsonObject



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/sg_mrt.rb', line 87

def to_json
  hash = {}
  hash[:code] = @code
  hash[:name] = @name
  hash[:stations] = @stations.inject([]) do |ret_station_array, station|
    station_hash = {}
    station_hash[:name] = station.name
    station_hash[:codes] = station.codes
    ret_station_array << station_hash
  end 
  hash.to_json
end