# encoding: utf-8 require "afr_load/tv_program" module AfrLoad module Parser class << self def parse(document) month_lineup_doc = get_month_lineup(document) month_lineup_doc.map do |lineup| parse_month_lineup(lineup).compact end end def get_month_lineup(document) document.xpath("//div[@id='contents']/div").select do |contents_child| is_month_lineup(contents_child) end end def is_month_lineup(contents_child) return false if contents_child.attribute("id") == nil if contents_child.attribute("id").value =~ /[0-9]{6}/ true else false end end def parse_month_lineup(contents_child) contents_child.xpath("//div/div[@class='gogo_item']").map do |movie_node| data_block = movie_node.at_xpath("div[contains(@class, 'g_data_block')]") if data_block.at_xpath("h3/span[@class='jp']").text == "放送内容未定" puts "放送内容未定" next end year_country = data_block.at_xpath("div/span[@class='g_country_year']") year_country = year_country.text.split("◆") performer = data_block.xpath("div/div/div[2]/span[2]").text tv_program = TvProgram.new do |info| #