Class: GameFaqs::Review

Inherits:
Object
  • Object
show all
Includes:
Caching
Defined in:
lib/gamefaqs/review.rb

Constant Summary collapse

REVIEW_TYPES =
[:detailed, :full, :quick]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Review

Returns a new instance of Review.

Raises:

  • (ArgumentError)


9
10
11
12
# File 'lib/gamefaqs/review.rb', line 9

def initialize(options={})
  raise ArgumentError.new("Need at least the game and the review id") unless options[:game] && options[:id]
  @game, @id, @score, @author, @title, @type = options[:game], options[:id], options[:score], options[:author], options[:title], options[:type]
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



7
8
9
# File 'lib/gamefaqs/review.rb', line 7

def author
  @author
end

#gameObject (readonly)

Returns the value of attribute game.



7
8
9
# File 'lib/gamefaqs/review.rb', line 7

def game
  @game
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/gamefaqs/review.rb', line 7

def id
  @id
end

#scoreObject (readonly)

Returns the value of attribute score.



7
8
9
# File 'lib/gamefaqs/review.rb', line 7

def score
  @score
end

#titleObject (readonly)

Returns the value of attribute title.



7
8
9
# File 'lib/gamefaqs/review.rb', line 7

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/gamefaqs/review.rb', line 7

def type
  @type
end

Class Method Details

.all_for(game) ⇒ Object



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

def self.all_for(game)
  List.reviews(game)
end

.review_type(string) ⇒ Object



36
37
38
39
40
# File 'lib/gamefaqs/review.rb', line 36

def self.review_type(string)
  REVIEW_TYPES.each do |type|
    return type if string =~ /#{type}/i
  end
end

Instance Method Details

#created_atObject



28
29
30
# File 'lib/gamefaqs/review.rb', line 28

def created_at
  @created_at ||= Date.parse(parse_review[:created_at], "%m/%d/%y")
end

#score_to_iObject



18
19
20
21
22
# File 'lib/gamefaqs/review.rb', line 18

def score_to_i
  actual, max = @score.split("/")
  factor = 10 / max.to_i
  actual.to_i * factor
end

#textObject



24
25
26
# File 'lib/gamefaqs/review.rb', line 24

def text
  @text ||= parse_review[:text]
end

#to_sObject



14
15
16
# File 'lib/gamefaqs/review.rb', line 14

def to_s
  "#{@game}: #{@score} by #{author} (#{@title} [#{@type}])"
end