Class: ANN_Media

Inherits:
ANN
  • Object
show all
Defined in:
lib/ann_wrapper/ann_media.rb

Direct Known Subclasses

ANN_Anime, ANN_Manga

Instance Method Summary collapse

Instance Method Details

#alt_titlesHash

Returns hash of titles grouped by language abbreviation

Returns:

  • (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

Returns:

  • (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

Returns:

  • ([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

Returns:

  • ([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

Returns:



62
63
64
65
66
# File 'lib/ann_wrapper/ann_media.rb', line 62

def ratings(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

Returns:

  • ([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

Returns:

  • ([String])

    returns synopsis



27
# File 'lib/ann_wrapper/ann_media.rb', line 27

def synopsis; end

#themes[String]

Returns array of themes

Returns:

  • ([String])

    returns array of themes



31
# File 'lib/ann_wrapper/ann_media.rb', line 31

def themes; end

#title[String]

Returns title(s)

Returns:

  • ([String])

    returns title(s)



25
# File 'lib/ann_wrapper/ann_media.rb', line 25

def title; end

#vintage[String]

Returns array of vintage(s)

Returns:

  • ([String])

    returns array of vintage(s)



33
# File 'lib/ann_wrapper/ann_media.rb', line 33

def vintage; end