Class: Tmdb::Genre

Inherits:
Object
  • Object
show all
Defined in:
lib/themoviedb/genre.rb

Constant Summary collapse

@@fields =
[
	:id,
	:page,
	:total_pages,
	:total_results,
	:results
]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Genre

Returns a new instance of Genre


3
4
5
6
7
8
9
# File 'lib/themoviedb/genre.rb', line 3

def initialize(attributes={})
  attributes.each do |key, value|
    if self.respond_to?(key.to_sym)
      self.instance_variable_set("@#{key}", value)
    end
  end
end

Class Method Details

.detail(id, conditions = {}) ⇒ Object


37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/themoviedb/genre.rb', line 37

def self.detail(id, conditions={})
	url = "/genre/#{id}/movies"
	if !conditions.empty?
		url << "?"
		conditions.each_with_index do |(key, value), index|
			url << "#{key}=#{value}"
			if index != conditions.length - 1
				url << "&"
			end
		end
	end
	search = Tmdb::Search.new(url)
	self.new(search.fetch_response)
end

.listObject


32
33
34
35
# File 'lib/themoviedb/genre.rb', line 32

def self.list
	search = Tmdb::Search.new("/genre/list")
	search.fetch_response
end

.search(query) ⇒ Object Also known as: find


24
25
26
# File 'lib/themoviedb/genre.rb', line 24

def self.search(query)
	self.detail(self.list['genres'].detect { |g| g['name'] == query }['id'])
end

Instance Method Details

#get_page(page_number, conditions = {}) ⇒ Object


56
57
58
59
60
61
# File 'lib/themoviedb/genre.rb', line 56

def get_page(page_number, conditions={})
	if page_number != @page and page_number > 0 and page_number <= @total_pages
		conditions.merge!({ :page => page_number })
		self.class.detail(id, conditions)
	end
end

#nameObject


52
53
54
# File 'lib/themoviedb/genre.rb', line 52

def name
	@name ||= self.class.list['genres'].detect { |g| g['id'] == @id }['name']
end