Class: ANN_Media
Instance Method Summary collapse
-
#alt_titles ⇒ Hash
Returns hash of titles grouped by language abbreviation.
-
#create_methods(obj, dictionary) ⇒ Object
create methods inside calling object.
-
#find_info(obj, key) ⇒ Nokogiri::XML::NodeSet
Return all info with provided key.
-
#genres ⇒ [String]
Returns array of genres.
-
#images ⇒ [ANN_Image]
Returns array of ANN_Image.
-
#ratings(obj) ⇒ [ANN_Rating]
Returns array of ANN_Episode.
-
#staff(obj) ⇒ [ANN_Staff]
Returns array of ANN_Staff.
-
#synopsis ⇒ [String]
Returns synopsis.
-
#themes ⇒ [String]
Returns array of themes.
-
#title ⇒ [String]
Returns title(s).
-
#vintage ⇒ [String]
Returns array of vintage(s).
Instance Method Details
#alt_titles ⇒ Hash
Returns hash of titles grouped by language abbreviation
52 53 54 55 56 57 58 59 |
# File 'lib/ann_wrapper/ann_media.rb', line 52 def alt_titles titles = find_info("Alternative title").group_by {|title| title['lang']} titles.each do |key, value| value.map! do |title| title.content end end end |
#create_methods(obj, dictionary) ⇒ Object
create methods inside calling object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ann_wrapper/ann_media.rb', line 11 def create_methods(obj, dictionary) dictionary.each do |name, key| create_method(name) do # find_info in calling object info = find_info(key) return nil if info.nil? info.map do |i| i.content end end end end |
#find_info(obj, key) ⇒ Nokogiri::XML::NodeSet
Return all info with provided key
6 7 8 |
# File 'lib/ann_wrapper/ann_media.rb', line 6 def find_info(obj, key) obj.search("info[@type=\"#{key}\"]") end |
#genres ⇒ [String]
Returns array of genres
29 |
# File 'lib/ann_wrapper/ann_media.rb', line 29 def genres; end |
#images ⇒ [ANN_Image]
Returns array of ANN_Image
36 37 38 39 40 |
# File 'lib/ann_wrapper/ann_media.rb', line 36 def images @images ||= find_info("Picture").xpath("./img").map do |i| ANN_Image.new(i['src'], i['width'], i['height']) end end |
#ratings(obj) ⇒ [ANN_Rating]
Returns array of ANN_Episode
62 63 64 65 66 |
# File 'lib/ann_wrapper/ann_media.rb', line 62 def (obj) @ratings ||= obj.xpath("./ratings").map do |r| ANN_Rating.new(r['nb_votes'], r['weighted_score'], r['bayesian_score']) end end |
#staff(obj) ⇒ [ANN_Staff]
Returns array of ANN_Staff
43 44 45 46 47 48 49 |
# File 'lib/ann_wrapper/ann_media.rb', line 43 def staff(obj) @staff ||= obj.xpath("./staff").map do |s| task = s.at_xpath("task") person = s.at_xpath("person") ANN_Staff.new(person['id'], task.content, person.content) end end |
#synopsis ⇒ [String]
Returns synopsis
27 |
# File 'lib/ann_wrapper/ann_media.rb', line 27 def synopsis; end |
#themes ⇒ [String]
Returns array of themes
31 |
# File 'lib/ann_wrapper/ann_media.rb', line 31 def themes; end |
#title ⇒ [String]
Returns title(s)
25 |
# File 'lib/ann_wrapper/ann_media.rb', line 25 def title; end |
#vintage ⇒ [String]
Returns array of vintage(s)
33 |
# File 'lib/ann_wrapper/ann_media.rb', line 33 def vintage; end |