Class: SgMRT::Station
- Inherits:
-
Object
- Object
- SgMRT::Station
- Defined in:
- lib/sg_mrt.rb
Constant Summary collapse
- @@cache =
{}
Instance Attribute Summary collapse
-
#codes ⇒ Object
Returns the value of attribute codes.
-
#lines ⇒ Object
Returns the value of attribute lines.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
- .all ⇒ Object
- .cached ⇒ Object
-
.define_helpers(meths) ⇒ Object
Defines line helpers.
- .find_by_code(code) ⇒ Object
- .find_by_name(name) ⇒ Object
Instance Method Summary collapse
-
#initialize(name, code = nil) ⇒ Station
constructor
A new instance of Station.
Constructor Details
#initialize(name, code = nil) ⇒ Station
Returns a new instance of Station.
117 118 119 120 121 122 |
# File 'lib/sg_mrt.rb', line 117 def initialize(name, code = nil) @name = name @lines = [] @codes = [] @codes << code if code end |
Instance Attribute Details
#codes ⇒ Object
Returns the value of attribute codes.
114 115 116 |
# File 'lib/sg_mrt.rb', line 114 def codes @codes end |
#lines ⇒ Object
Returns the value of attribute lines.
114 115 116 |
# File 'lib/sg_mrt.rb', line 114 def lines @lines end |
#name ⇒ Object
Returns the value of attribute name.
114 115 116 |
# File 'lib/sg_mrt.rb', line 114 def name @name end |
Class Method Details
.cached ⇒ Object
138 139 140 |
# File 'lib/sg_mrt.rb', line 138 def cached @@cache end |
.define_helpers(meths) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/sg_mrt.rb', line 150 def define_helpers(meths) meths.each do |code| define_method("#{code.downcase}?") do @lines.include?(code.upcase) end define_method("#{code}?") do @lines.include?(code.upcase) end end end |
.find_by_code(code) ⇒ Object
134 135 136 |
# File 'lib/sg_mrt.rb', line 134 def find_by_code(code) @@cache[code] ||= all.find{|x| x.codes.include?(code)} end |
.find_by_name(name) ⇒ Object
130 131 132 |
# File 'lib/sg_mrt.rb', line 130 def find_by_name(name) @@cache[name] ||= all.find{|x| x.name == name} end |