lib/fandango/theater.rb in fandango-1.0.0 vs lib/fandango/theater.rb in fandango-2.0.0

- old
+ new

@@ -1,50 +1,59 @@ module Fandango module Theater - class << self + module_function - def initialize(entry) - @entry = entry - end + def parse(item_node) + hash = {} - def parse(item_node, description_node = nil) - description_node ||= Fandango::Parser.parse_description(item_node) - name = parse_name(item_node) - id = parse_id(item_node) - address = parse_address(description_node) - postal_code = parse_postal_code(address) + description_node = parse_description_node(item_node) - { - name: name, - id: id, - address: address, - postal_code: postal_code, - } - end + hash[:name] = parse_name(item_node) + hash[:id] = parse_id(item_node) + hash[:address] = parse_address(description_node) + hash[:postal_code] = parse_postal_code(hash[:address]) + hash[:showtimes_link] = parse_showtimes_link(item_node) + hash[:movies] = parse_movies(description_node) - private + hash + end - def parse_name(item_node) - item_node.at_css('title').content - end + # Description content is in the form of HTML wrapped in CDATA. + # Parse it and return a parsed Nokogiri node. + def parse_description_node(item_node) + cdata = item_node.at_css('description') + Nokogiri::HTML(cdata.content) + end - # E.g. 'aaicu' in http://www.fandango.com/northpark7_aaicu/theaterpage - def parse_id(item_node) - item_node. - at_css('link'). - content. - match(%r{fandango\.com/.*_(?<id>.*)/theaterpage})[:id] - end + def parse_name(item_node) + item_node.at_css('title').content.strip + end - def parse_address(description_node) - description_node.at_css('p').content - end + # E.g. 'aaicu' in http://www.fandango.com/northpark7_aaicu/theaterpage + def parse_id(item_node) + item_node. + at_css('link'). + content. + match(%r{fandango\.com/.*_(?<id>.*)/theaterpage})[:id] + end - def parse_postal_code(address) - address.match(/(?<postal_code>\d+)$/)[:postal_code] - end + def parse_address(description_node) + description_node.at_css('p').content + end + def parse_postal_code(address) + address.match(/(?<postal_code>\d+)$/)[:postal_code] + end + + def parse_showtimes_link(item_node) + item_node.at_css('link').content.strip + end + + def parse_movies(description_node) + description_node.css('li').map do |li| + Movie.parse(li) + end end end end