Class: ImdbCelebrity::Parser::NokogiriParser::SearchParser
- Inherits:
-
NokogiriParser
- Object
- NokogiriParser
- ImdbCelebrity::Parser::NokogiriParser::SearchParser
- Defined in:
- lib/imdb_celebrity/parser/nokogiri_parser/search_parser.rb
Instance Method Summary collapse
- #exact_match? ⇒ Boolean
-
#initialize(uri) ⇒ SearchParser
constructor
A new instance of SearchParser.
- #parse_celebrities(parser) ⇒ Object
Constructor Details
#initialize(uri) ⇒ SearchParser
Returns a new instance of SearchParser.
7 8 9 |
# File 'lib/imdb_celebrity/parser/nokogiri_parser/search_parser.rb', line 7 def initialize uri super uri end |
Instance Method Details
#exact_match? ⇒ Boolean
11 12 13 |
# File 'lib/imdb_celebrity/parser/nokogiri_parser/search_parser.rb', line 11 def exact_match? !document.at("h3[text()^='Overview']").nil? end |
#parse_celebrities(parser) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/imdb_celebrity/parser/nokogiri_parser/search_parser.rb', line 15 def parse_celebrities parser document.search('a[@href^="/name/nm"]').reject do |element| element.to_html..empty? || element.parent.to_html =~ /media from/i end.map do |element| id = element['href'][/\d+/] data = element.parent.to_html.split("<br />") if !data[0].nil? && !data[1].nil? && data[0] =~ /img/ title = data[1] else title = data[0] end title = title..imdb_unescape_html title.gsub!(/\s+\(\d{4}\)$/, '') [id, title, parser] end end |