Class: MovieShowTimes::Parser
- Inherits:
-
Object
- Object
- MovieShowTimes::Parser
- Defined in:
- lib/movie_show_times/parser.rb
Instance Attribute Summary collapse
-
#movies ⇒ Object
Returns the value of attribute movies.
-
#theaters ⇒ Object
Returns the value of attribute theaters.
Instance Method Summary collapse
-
#initialize(language = 'en') ⇒ Parser
constructor
A new instance of Parser.
- #parse_movie_info(info_line) ⇒ Object
- #parse_show_times(doc) ⇒ Object
Constructor Details
#initialize(language = 'en') ⇒ Parser
Returns a new instance of Parser.
10 11 12 13 14 15 16 |
# File 'lib/movie_show_times/parser.rb', line 10 def initialize(language = 'en') @language = language @language_parser = MovieShowTimes::LanguageParser.new(language) @genre_parser = MovieShowTimes::GenreParser.new(language) @theaters = Hash.new @movies = Hash.new end |
Instance Attribute Details
#movies ⇒ Object
Returns the value of attribute movies.
8 9 10 |
# File 'lib/movie_show_times/parser.rb', line 8 def movies @movies end |
#theaters ⇒ Object
Returns the value of attribute theaters.
8 9 10 |
# File 'lib/movie_show_times/parser.rb', line 8 def theaters @theaters end |
Instance Method Details
#parse_movie_info(info_line) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/movie_show_times/parser.rb', line 51 def parse_movie_info(info_line) duration = ChronicDuration.parse(info_line) genre = @genre_parser.parse(info_line) language = @language_parser.parse(info_line) { :duration => duration, :genre => genre, :language => language } end |
#parse_show_times(doc) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/movie_show_times/parser.rb', line 18 def parse_show_times(doc) theater_elements = doc.xpath( "//div[@class='movie_results']/div[@class='theater' and .//h2/a]" ) theater_elements.each do |t| theater_name = t.search(".//h2[@class='name']/a/text()").text theater_info = t.search(".//div[@class='info']/text()").text showtimes = [] movie_elements = t.search(".//div[@class='showtimes']//div[@class='movie']") movie_elements.each do |m| movie_name = m.search(".//div[@class='name']/a/text()").text.strip movie_info_line = m.search(".//span[@class='info']/text()").text movie_info = parse_movie_info(movie_info_line) @movies[movie_name] = { :name => movie_name, :info => movie_info } if @movies[movie_name].nil? movie_times = m.search(".//div[@class='times']/span/text()") times = [] movie_times.each do |mt| time = mt.text.strip times << time end showtimes << { :name => movie_name, :language => movie_info[:language], :times => times } end @theaters[theater_name] = { :name => theater_name, :info => theater_info, :movies => showtimes } end end |