Class: Bdz::Parser::Schedule

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

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Schedule

Returns a new instance of Schedule.



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

def initialize(response)
  @response = response
end

Instance Method Details

#parseObject



8
9
10
11
# File 'lib/bdz/parser/schedule.rb', line 8

def parse
  @content = Nokogiri::HTML(@response.body)
  parse_content
end

#parse_contentObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bdz/parser/schedule.rb', line 13

def parse_content
  begin
    @content.css('tbody tr').take(@content.css('tbody tr').size - 1).collect do |train|
       t = Bdz::Train.new(
             :id => train.css('td a')[0].text,
             :type => train.css('td')[1].text,
             :leaves => train.css('td')[2].text,
             :arrives => train.css('td')[3].text,
           )
    end
  rescue
    return []
  end
end