Class: Traffic::Providers::Anwb

Inherits:
Object
  • Object
show all
Defined in:
lib/traffic/providers/anwb.rb

Constant Summary collapse

HTML_FEED =
"http://flitsapp.nl/ios/anwb/"

Instance Method Summary collapse

Constructor Details

#initialize(archived_data = nil) ⇒ Anwb

Returns a new instance of Anwb.



9
10
11
# File 'lib/traffic/providers/anwb.rb', line 9

def initialize(archived_data=nil)
  @data = Nokogiri::HTML::Document.parse(archived_data) if archived_data
end

Instance Method Details

#countObject



21
22
23
# File 'lib/traffic/providers/anwb.rb', line 21

def count
  count_info[0].text[/Totaal aantal meldingen: (.+)/, 1].to_i
end

#each_item(&block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/traffic/providers/anwb.rb', line 29

def each_item(&block)
  html.css(".message").each do |entry|
    item = Struct.new(*ITEM_ATTRIBUTES).new

    item.road = entry.css("span.roadnumber_a,span.roadnumber_n").text
    data = entry.css("strong.desc_short").text
    item.from = data[/(.*) - (.*)/, 1]
    item.to = data[/(.*) - (.*)/, 2]

    item.description = entry.css("p.desc_long").children.first.text
    hmp = entry.css("p.desc_long span.hmp")
    item.from_location = hmp[1].text.to_f
    item.to_location = hmp[0].text.to_f

    unless entry["class"].include?("roadworks")
      item.length = entry.css("span.km").text.to_f
    else 
      item.length = (hmp[1].text.to_f - hmp[0].text.to_f).abs.round(1)
    end

    yield item
  end
end

#sizeObject



25
26
27
# File 'lib/traffic/providers/anwb.rb', line 25

def size
  count_info[1].text[/Totale lengte: (.+) km/, 1].to_i
end

#timestampObject



17
18
19
# File 'lib/traffic/providers/anwb.rb', line 17

def timestamp
  Time.parse(count_info[2].text[/Laatste update: (.+) uur/, 1])
end

#trafficObject



13
14
15
# File 'lib/traffic/providers/anwb.rb', line 13

def traffic
  !(count_info[0].text =~ /Totaal aantal meldingen: 0/)
end