Class: RTV::Fetcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFetcher

Returns a new instance of Fetcher.



93
94
95
96
# File 'lib/rtv.rb', line 93

def initialize
  @options = {}
  @shows = Program.new
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



91
92
93
# File 'lib/rtv.rb', line 91

def config
  @config
end

#optionsObject

Returns the value of attribute options.



91
92
93
# File 'lib/rtv.rb', line 91

def options
  @options
end

Instance Method Details

#extract_shows(doc) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/rtv.rb', line 108

def extract_shows doc
  if @options[:format] == 'search'
    daten = (doc/"div[@id='titel-uebersicht']")
    daten.each do |datum|
      zeiten = datum.parent.parent.parent.next_sibling
      unless zeiten.nil?
        zeiten = zeiten.search("span.tv-sendung-uhrzeit")
      else
        puts "Keine Suchergebnisse!" if $DEBUG
        raise NotFoundException, "Keine Suchergebnisse!"
      end
      zeiten.each do |zeit|
        show = Show.new
        show.options = @config
        show.time = zeit.innerText
        show.desc, show.showview = time_to_desc_and_showview(zeit)
        show.name = time_to_name(zeit)
        show.channel = time_to_channel(zeit)
        show.date = datum.innerText[/^\D*(.+) Suchergebnis/, 1]
        add_show show
      end
    end
  else
    zeiten = (doc/"span.tv-sendung-uhrzeit")
    zeiten.each do |zeit|
      show = Show.new
      show.options = @config
      show.time = zeit.innerText
      show.desc, show.showview = time_to_desc_and_showview(zeit)
      show.name = time_to_name(zeit)
      show.channel = time_to_channel(zeit)
      add_show show
    end
  end
end

#fetchObject



98
99
100
101
102
103
104
105
106
# File 'lib/rtv.rb', line 98

def fetch
  while search_results?(doc = get_hdoc)
    extract_shows doc
    @options[:offset] += 1
    print "." if $DEBUG
  end
  puts if $DEBUG
  return @shows
end