Class: TitleBuilder
- Inherits:
-
Object
- Object
- TitleBuilder
- Defined in:
- lib/net_flix/builders/title_builder.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data) ⇒ TitleBuilder
constructor
A new instance of TitleBuilder.
- #set_actors ⇒ Object
- #set_box_art ⇒ Object
- #set_delivery_formats ⇒ Object
- #set_genres ⇒ Object
- #set_id ⇒ Object
- #set_release_year ⇒ Object
- #set_title ⇒ Object
- #set_web_page ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(data) ⇒ TitleBuilder
Returns a new instance of TitleBuilder.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/net_flix/builders/title_builder.rb', line 18 def initialize(data) @data = data @title = NetFlix::Title.new set_actors set_delivery_formats set_genres set_id set_release_year set_title set_web_page set_box_art end |
Class Method Details
.from_xml(xml) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/net_flix/builders/title_builder.rb', line 3 def self.from_xml(xml) return [] unless xml nxml = Nokogiri.XML(xml) titles(nxml).map do |data| TitleBuilder.new(data).title end end |
.titles(noko_xml) ⇒ Object
13 14 15 16 |
# File 'lib/net_flix/builders/title_builder.rb', line 13 def self.titles(noko_xml) titles = noko_xml.xpath('//catalog_title') titles.empty? ? noko_xml.xpath('//title_index_item') : titles end |
Instance Method Details
#set_actors ⇒ Object
60 61 62 |
# File 'lib/net_flix/builders/title_builder.rb', line 60 def set_actors @title.actors = ActorBuilder.from_movie(@data) end |
#set_box_art ⇒ Object
64 65 66 67 68 |
# File 'lib/net_flix/builders/title_builder.rb', line 64 def set_box_art box_arts = @data.search('box_art') @title.box_art = {} %w{ small medium large }.each { |size| @title.box_art[size] = box_arts.attr(size).value } end |
#set_delivery_formats ⇒ Object
52 53 54 |
# File 'lib/net_flix/builders/title_builder.rb', line 52 def set_delivery_formats @title.delivery_formats = FormatBuilder.from_movie(@data) end |
#set_genres ⇒ Object
56 57 58 |
# File 'lib/net_flix/builders/title_builder.rb', line 56 def set_genres @title.genres = @data.search('category[@scheme="http://api.netflix.com/categories/genres"]').map{|f| f['label'] } end |
#set_id ⇒ Object
32 33 34 35 |
# File 'lib/net_flix/builders/title_builder.rb', line 32 def set_id node = @data.search('id').first @title.id = node.content if node end |
#set_release_year ⇒ Object
37 38 39 40 |
# File 'lib/net_flix/builders/title_builder.rb', line 37 def set_release_year node = @data.search('release_year').first @title.release_year = node.content if node end |
#set_title ⇒ Object
42 43 44 45 |
# File 'lib/net_flix/builders/title_builder.rb', line 42 def set_title node = @data.search('title').first @title.title = node['regular'] || node.content if node end |
#set_web_page ⇒ Object
47 48 49 50 |
# File 'lib/net_flix/builders/title_builder.rb', line 47 def set_web_page node = @data.search('link[@title="web page"]').first @title.web_page = node['href'] if node end |
#title ⇒ Object
70 71 72 |
# File 'lib/net_flix/builders/title_builder.rb', line 70 def title @title end |