Class: SgMRT::Line
- Inherits:
-
Object
- Object
- SgMRT::Line
- Defined in:
- lib/sg_mrt.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#name ⇒ Object
Returns the value of attribute name.
-
#stations ⇒ Object
Returns the value of attribute stations.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(code = nil) ⇒ Line
constructor
A new instance of Line.
- #to_json ⇒ Object
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
#code ⇒ Object
Returns the value of attribute code.
80 81 82 |
# File 'lib/sg_mrt.rb', line 80 def code @code end |
#name ⇒ Object
Returns the value of attribute name.
80 81 82 |
# File 'lib/sg_mrt.rb', line 80 def name @name end |
#stations ⇒ Object
Returns the value of attribute stations.
80 81 82 |
# File 'lib/sg_mrt.rb', line 80 def stations @stations end |
Class Method Details
.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_json ⇒ Object
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 |