Class: Tmdb::Genre
- Inherits:
-
Object
- Object
- Tmdb::Genre
- Defined in:
- lib/themoviedb-jzg/genre.rb
Constant Summary collapse
- @@fields =
[ :id, :page, :total_pages, :total_results, :results ]
Class Method Summary collapse
Instance Method Summary collapse
- #get_page(page_number, conditions = {}) ⇒ Object
-
#initialize(attributes = {}) ⇒ Genre
constructor
A new instance of Genre.
- #name ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Genre
Returns a new instance of Genre.
3 4 5 6 7 8 9 |
# File 'lib/themoviedb-jzg/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-jzg/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 |
.list ⇒ Object
32 33 34 35 |
# File 'lib/themoviedb-jzg/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-jzg/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-jzg/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 |
#name ⇒ Object
52 53 54 |
# File 'lib/themoviedb-jzg/genre.rb', line 52 def name @name ||= self.class.list['genres'].detect { |g| g['id'] == @id }['name'] end |