Sha256: 5d90d341d107e1f6ee4a5fb95b76fbbf850f75ee1244f2c00abf6d2ea2c21c9b
Contents?: true
Size: 1.05 KB
Versions: 2
Compression:
Stored size: 1.05 KB
Contents
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/.*_(?<id>\d+)/})[:id] end # <div class="showtimes-movie-rating-runtime"> # <!-- Display rating --> # R , # <!-- Display runtime --> # 1 hr 41 min # </div> def parse_runtime(node) rating_runtime = node.at_css('.showtimes-movie-rating-runtime') %r{(?<hour>\d+)\s+hr\s+(?<min>\d+)} =~ rating_runtime.content begin Integer(hour) * 60 + Integer(min) rescue TypeError #puts rating_runtime end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
fandango-2.1.0 | lib/fandango/movie.rb |
fandango-2.0.0 | lib/fandango/movie.rb |