Class: GameFaqs::Game

Inherits:
Object
  • Object
show all
Defined in:
lib/gamefaqs/game.rb

Constant Summary collapse

GENRES =
{ "Action" => "54", "Action-Adventure" => "163", "Adventure" => "50", "Driving" => "47", "Miscellaneous" => "49", "Role-Playing" => "48", "Simulation" => "46", "Sports" => "43", "Strategy" => "45"}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, platform, id) ⇒ Game

Returns a new instance of Game.



8
9
10
11
12
13
# File 'lib/gamefaqs/game.rb', line 8

def initialize(name, platform, id)
  @name = name
  @platform = platform
  @id = id
  @homepage = "#{@platform.homepage}home/#{@id}.html"
end

Instance Attribute Details

#codesObject (readonly)

Returns the value of attribute codes.



6
7
8
# File 'lib/gamefaqs/game.rb', line 6

def codes
  @codes
end

#faqsObject (readonly)

Returns the value of attribute faqs.



6
7
8
# File 'lib/gamefaqs/game.rb', line 6

def faqs
  @faqs
end

#homepageObject (readonly)

Returns the value of attribute homepage.



6
7
8
# File 'lib/gamefaqs/game.rb', line 6

def homepage
  @homepage
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/gamefaqs/game.rb', line 6

def name
  @name
end

#platformObject (readonly)

Returns the value of attribute platform.



6
7
8
# File 'lib/gamefaqs/game.rb', line 6

def platform
  @platform
end

Class Method Details

.find(game, platform) ⇒ Object



40
41
42
# File 'lib/gamefaqs/game.rb', line 40

def self.find(game, platform)
  Search.game(game, platform)
end

Instance Method Details

#average_score(review_type = nil) ⇒ Object



31
32
33
34
# File 'lib/gamefaqs/game.rb', line 31

def average_score(review_type=nil)
  sum = reviews(review_type).map{|r| r.score_to_i}.inject{|memo, score| memo + score}
  sum ? (sum / reviews(review_type).size.to_f) : -1
end

#average_score_to_sObject



36
37
38
# File 'lib/gamefaqs/game.rb', line 36

def average_score_to_s
  "%.2f - #{to_s}" % average_score
end

#questionsObject



27
28
29
# File 'lib/gamefaqs/game.rb', line 27

def questions
  List.questions(self)
end

#reviews(review_type = nil) ⇒ Object



23
24
25
# File 'lib/gamefaqs/game.rb', line 23

def reviews(review_type=nil)
  List.reviews(self, review_type)
end

#to_sObject



19
20
21
# File 'lib/gamefaqs/game.rb', line 19

def to_s
  "#{@name} [#{platform}]"
end