Class: Bdz::Train
- Inherits:
-
Object
- Object
- Bdz::Train
- Defined in:
- lib/bdz/train.rb
Instance Attribute Summary collapse
-
#arrives ⇒ Object
readonly
Returns the value of attribute arrives.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#leaves ⇒ Object
readonly
Returns the value of attribute leaves.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(params) ⇒ Train
constructor
A new instance of Train.
Constructor Details
#initialize(params) ⇒ Train
Returns a new instance of Train.
7 8 9 10 11 12 13 14 |
# File 'lib/bdz/train.rb', line 7 def initialize (params) return if params.nil? params.each do |key, value| name = key.to_s instance_variable_set("@#{name}", value) if respond_to?(name) end end |
Instance Attribute Details
#arrives ⇒ Object (readonly)
Returns the value of attribute arrives.
5 6 7 |
# File 'lib/bdz/train.rb', line 5 def arrives @arrives end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/bdz/train.rb', line 3 def id @id end |
#leaves ⇒ Object (readonly)
Returns the value of attribute leaves.
4 5 6 |
# File 'lib/bdz/train.rb', line 4 def leaves @leaves end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/bdz/train.rb', line 6 def type @type end |
Instance Method Details
#as_json ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/bdz/train.rb', line 16 def as_json hash = {} self.instance_variables.each do |var| hash[var.to_s.gsub("@", "")] = self.instance_variable_get var end hash.to_json end |