Class: CtaTrack::Predictions

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Predictions

Returns a new instance of Predictions.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/predictions.rb', line 4

def initialize(args) 
  @result = {} 
  API.predictions(args).root.xpath("prd").each do |node|
    time = node.xpath('tmstmp').text
    year = time[(0..3)].to_i
    month = time[(4..5)].to_i
    day = time[(6..7)].to_i
    hour = time[(9..10)].to_i
    minute = time[(12..13)].to_i

    @result[node.xpath('vid').text] = {
      :stpnm => node.xpath('stpnm').text,
      :stpid => node.xpath('stpid').text.to_i,
      :vid => node.xpath("vid").text.to_i,
      :dstp => node.xpath("dstp").text.to_i,
      :rt => node.xpath("rt").text, 
      :rtdir => node.xpath("rtdir").text,
      :des => node.xpath("des").text,
      :prdtm => node.xpath("prdtm").text, 
      :dly => node.xpath("dly").text,
      :timestamp => DateTime.new(year, month, day, hour, minute)
    } 
  end 
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, vid, *arguments, &block) ⇒ Object



32
33
34
# File 'lib/predictions.rb', line 32

def method_missing(method_name, vid, *arguments, &block)
  @result[vid][method_name.to_sym]
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



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

def result
  @result
end

Instance Method Details

#keysObject



29
30
31
# File 'lib/predictions.rb', line 29

def keys
  @result.keys
end

#respond_to?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/predictions.rb', line 35

def respond_to?(method_name, include_private = false)
  @result[@result.keys[0]].include?("#{method_name}".to_sym)
end