Class: Bdz::Train

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#arrivesObject (readonly)

Returns the value of attribute arrives.



5
6
7
# File 'lib/bdz/train.rb', line 5

def arrives
  @arrives
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/bdz/train.rb', line 3

def id
  @id
end

#leavesObject (readonly)

Returns the value of attribute leaves.



4
5
6
# File 'lib/bdz/train.rb', line 4

def leaves
  @leaves
end

#typeObject (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_jsonObject



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