module AfrLoad::Parser

Public Class Methods

get_month_lineup(document) click to toggle source
# File lib/afr_load/parser.rb, line 15
def get_month_lineup(document)
  document.xpath("//div[@id='contents']/div").select do |contents_child|
    is_month_lineup(contents_child)
  end
end
is_month_lineup(contents_child) click to toggle source
# File lib/afr_load/parser.rb, line 21
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
parse(document) click to toggle source
# File lib/afr_load/parser.rb, line 8
def parse(document)
  month_lineup_doc = get_month_lineup(document)
  month_lineup_doc.map do |lineup|
    parse_month_lineup(lineup).compact
  end
end
parse_month_lineup(contents_child) click to toggle source
# File lib/afr_load/parser.rb, line 30
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|
      #<div class="gogo_item" data-oaStart="2017053113350000" data-oaEnd="2017053115400000">
      info.on_air_start = movie_node.get("data-oaStart")
      info.on_air_end = movie_node.get("data-oaEnd")
      info.on_air_date = movie_node.at_xpath("span[contains(@class, 'g_day')]").text
      info.title_ja = data_block.at_xpath("h3/span[@class='jp']").text
      info.title = data_block.at_xpath("h3/span[contains(@class, 'en')]").text
      info.released_year = year_country[0]
      info.released_country = year_country[1]
      info.movie_director = data_block.xpath("div/div/div[1]/span[2]").text
      info.leading_actor = performer.split("/")[0]
      info.supporting_actor = performer.split("/")[1]
    end
  end
end