Class: OneRuby::Movie

Inherits:
Object
  • Object
show all
Defined in:
lib/one_ruby/movie.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#academy_award_nominationsObject

Returns the value of attribute academy_award_nominations.



3
4
5
# File 'lib/one_ruby/movie.rb', line 3

def academy_award_nominations
  @academy_award_nominations
end

#academy_award_winsObject

Returns the value of attribute academy_award_wins.



3
4
5
# File 'lib/one_ruby/movie.rb', line 3

def academy_award_wins
  @academy_award_wins
end

#box_office_revenue_in_millionsObject

Returns the value of attribute box_office_revenue_in_millions.



3
4
5
# File 'lib/one_ruby/movie.rb', line 3

def box_office_revenue_in_millions
  @box_office_revenue_in_millions
end

#budget_in_millionsObject

Returns the value of attribute budget_in_millions.



3
4
5
# File 'lib/one_ruby/movie.rb', line 3

def budget_in_millions
  @budget_in_millions
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/one_ruby/movie.rb', line 3

def id
  @id
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/one_ruby/movie.rb', line 3

def name
  @name
end

#rotten_tomatoes_scoreObject

Returns the value of attribute rotten_tomatoes_score.



3
4
5
# File 'lib/one_ruby/movie.rb', line 3

def rotten_tomatoes_score
  @rotten_tomatoes_score
end

#runtime_in_minutesObject

Returns the value of attribute runtime_in_minutes.



3
4
5
# File 'lib/one_ruby/movie.rb', line 3

def runtime_in_minutes
  @runtime_in_minutes
end

Class Method Details

.find(id) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/one_ruby/movie.rb', line 12

def self.find(id)
  results = OneRuby::Client.get "movie/#{id}"
  docs = results['docs']
  if docs.empty?
    nil
  else
    transform(docs.first)
  end
end

.listObject



6
7
8
9
10
# File 'lib/one_ruby/movie.rb', line 6

def self.list
  results = OneRuby::Client.get 'movie'
  movies = results['docs']
  movies.map { |r| transform(r) }
end

.transform(response) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/one_ruby/movie.rb', line 22

def self.transform(response)
  movie = Movie.new
  movie.id = response['_id']
  movie.name = response['name']
  movie.runtime_in_minutes = response['runtimeInMinutes']
  movie.budget_in_millions = response['budgetInMillions']
  movie.box_office_revenue_in_millions = response['boxOfficeRevenueInMillions']
  movie.academy_award_nominations = response['academyAwardNominations']
  movie.academy_award_wins = response['academyAwardWins']
  movie.rotten_tomatoes_score = response['rottenTomatoesScore']
  movie
end