Module: Fandango::Movie
- Defined in:
- lib/fandango/movie.rb
Class Method Summary collapse
- .parse(node) ⇒ Object
-
.parse_id(a_tag) ⇒ Object
E.g.
-
.parse_runtime(node) ⇒ Object
<div class=“showtimes-movie-rating-runtime”> <!– Display rating –> R , <!– Display runtime –> 1 hr 41 min </div>.
- .parse_title(a_tag) ⇒ Object
Class Method Details
.parse(node) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/fandango/movie.rb', line 6 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 |
.parse_id(a_tag) ⇒ Object
E.g. ‘141081’ in fandango.com/the+adventures+of+tintin+3d_141081/movietimes
25 26 27 |
# File 'lib/fandango/movie.rb', line 25 def parse_id(a_tag) a_tag['href'].match(%r{fandango\.com/.*_(?<id>\d+)/})[:id] end |
.parse_runtime(node) ⇒ Object
<div class=“showtimes-movie-rating-runtime”> <!– Display rating –> R ,
<!-- Display runtime -->
1 hr 41 min </div>
35 36 37 38 39 40 41 42 43 |
# File 'lib/fandango/movie.rb', line 35 def parse_runtime(node) = node.at_css('.showtimes-movie-rating-runtime') %r{(?<hour>\d+)\s+hr\s+(?<min>\d+)} =~ .content begin Integer(hour) * 60 + Integer(min) rescue TypeError #puts rating_runtime end end |
.parse_title(a_tag) ⇒ Object
20 21 22 |
# File 'lib/fandango/movie.rb', line 20 def parse_title(a_tag) a_tag.content end |