Class: ProgramTV::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/program-tv/writer.rb

Instance Method Summary collapse

Constructor Details

#initialize(data, destination) ⇒ Writer



7
8
9
10
# File 'lib/program-tv/writer.rb', line 7

def initialize(data, destination)
  @data = data
  @destination = destination
end

Instance Method Details

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/program-tv/writer.rb', line 12

def run
  @data.each do |schedule|
    today_schedule = []
    if File.exist?(xml_path(schedule))
      File.open(xml_path(schedule), "r+") do |file|
        today_schedule = Hash.from_xml(file.read)[:tv][:programme].map do |e|
          e[:attributes][:title] = e[:title]
          e[:attributes]
        end
      end
    end
    File.open(xml_path(schedule), "w+") do |file|
      file.write(build_xml(today_schedule + schedule))
    end
  end
end