Class: Traffic::Providers::FileIndex

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

Constant Summary collapse

RSS_FEED =
"http://www.fileindex.nl/rss.php"

Instance Method Summary collapse

Constructor Details

#initialize(archived_data = nil) ⇒ FileIndex

Returns a new instance of FileIndex.



8
9
10
# File 'lib/traffic/providers/file_index.rb', line 8

def initialize(archived_data=nil)
  @data = Feedzirra::Feed.parse(archived_data) if archived_data
end

Instance Method Details

#countObject



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

def count
  rss.description[/(\d+) files?.+van .+ km./, 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
52
# File 'lib/traffic/providers/file_index.rb', line 29

def each_item(&block)
  rss.entries.each do |entry|
    item = Struct.new(:road, :from, :to, :from_location, :to_location, :location, :length, :description, :cause, :status).new
    data = entry.title.match /(.+?) van (.+) richting (.+) (.+) km/
    item.road = data[1]
    item.from = data[2]
    item.to = data[3]
    item.length = data[4].to_f

    data = entry.summary.match /(.+) tussen (.+?)( door (.+))? HMP([\d\.]+) .+ HMP([\d\.]+)\s*(.*)/
    if data.nil?
      item.description = entry.summary
    else
      item.description = data[1]
      item.location = data[2]
      item.cause = data[4]
      item.from_location = data[5].to_f
      item.to_location = data[6].to_f
      item.status = data[7]
    end
    
    yield item
  end
end

#sizeObject



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

def size
  rss.description[/\d+ files?.+van (.+) km./, 1].to_i
end

#timestampObject



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

def timestamp
  time_string = translate(rss.title.gsub(/Fileindex.nl actuele files /, ""))
  Time.parse(time_string)
end

#trafficObject



12
13
14
# File 'lib/traffic/providers/file_index.rb', line 12

def traffic
  !(rss.description =~ /Er zijn geen files./)
end