Module: Fandango::Theater
- Defined in:
- lib/fandango/theater.rb
Class Method Summary collapse
- .parse(item_node) ⇒ Object
- .parse_address(description_node) ⇒ Object
-
.parse_description_node(item_node) ⇒ Object
Description content is in the form of HTML wrapped in CDATA.
-
.parse_id(item_node) ⇒ Object
E.g.
- .parse_movies(description_node) ⇒ Object
- .parse_name(item_node) ⇒ Object
- .parse_postal_code(address) ⇒ Object
- .parse_showtimes_link(item_node) ⇒ Object
Class Method Details
.parse(item_node) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/fandango/theater.rb', line 6 def parse(item_node) hash = {} description_node = parse_description_node(item_node) 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) hash end |
.parse_address(description_node) ⇒ Object
40 41 42 |
# File 'lib/fandango/theater.rb', line 40 def parse_address(description_node) description_node.at_css('p').content end |
.parse_description_node(item_node) ⇒ Object
Description content is in the form of HTML wrapped in CDATA. Parse it and return a parsed Nokogiri node.
23 24 25 26 |
# File 'lib/fandango/theater.rb', line 23 def parse_description_node(item_node) cdata = item_node.at_css('description') Nokogiri::HTML(cdata.content) end |
.parse_id(item_node) ⇒ Object
E.g. ‘aaicu’ in www.fandango.com/northpark7_aaicu/theaterpage
33 34 35 36 37 38 |
# File 'lib/fandango/theater.rb', line 33 def parse_id(item_node) item_node. at_css('link'). content. match(%r{fandango\.com/.*_(?<id>.*)/theaterpage})[:id] end |
.parse_movies(description_node) ⇒ Object
52 53 54 55 56 |
# File 'lib/fandango/theater.rb', line 52 def parse_movies(description_node) description_node.css('li').map do |li| Movie.parse(li) end end |
.parse_name(item_node) ⇒ Object
28 29 30 |
# File 'lib/fandango/theater.rb', line 28 def parse_name(item_node) item_node.at_css('title').content.strip end |
.parse_postal_code(address) ⇒ Object
44 45 46 |
# File 'lib/fandango/theater.rb', line 44 def parse_postal_code(address) address.match(/(?<postal_code>\d+)$/)[:postal_code] end |
.parse_showtimes_link(item_node) ⇒ Object
48 49 50 |
# File 'lib/fandango/theater.rb', line 48 def parse_showtimes_link(item_node) item_node.at_css('link').content.strip end |