module Fandango module Movie module_function def parse(node) a_tag = node.at_css('a.showtimes-movie-title') || node.at_css('a') hash = { title: parse_title(a_tag), id: parse_id(a_tag), } if a_tag.attr(:class)&.include?('showtimes-movie-title') hash[:runtime] = parse_runtime(node) end hash end def parse_title(a_tag) a_tag.content end # E.g. '141081' in fandango.com/the+adventures+of+tintin+3d_141081/movietimes def parse_id(a_tag) a_tag['href'].match(%r{fandango\.com/.*_(?\d+)/})[:id] end #
# # R , # # 1 hr 41 min #
def parse_runtime(node) rating_runtime = node.at_css('.showtimes-movie-rating-runtime') %r{(?\d+)\s+hr\s+(?\d+)} =~ rating_runtime.content begin Integer(hour) * 60 + Integer(min) rescue TypeError #puts rating_runtime end end end end