Class: GameFaqs::FAQ

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ FAQ

Returns a new instance of FAQ.

Raises:

  • (ArgumentError)


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

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

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



3
4
5
# File 'lib/gamefaqs/faq.rb', line 3

def author
  @author
end

#created_atObject (readonly)

Returns the value of attribute created_at.



3
4
5
# File 'lib/gamefaqs/faq.rb', line 3

def created_at
  @created_at
end

#gameObject (readonly)

Returns the value of attribute game.



3
4
5
# File 'lib/gamefaqs/faq.rb', line 3

def game
  @game
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/gamefaqs/faq.rb', line 3

def id
  @id
end

#sizeObject (readonly)

Returns the value of attribute size.



3
4
5
# File 'lib/gamefaqs/faq.rb', line 3

def size
  @size
end

#titleObject (readonly)

Returns the value of attribute title.



3
4
5
# File 'lib/gamefaqs/faq.rb', line 3

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/gamefaqs/faq.rb', line 3

def type
  @type
end

#versionObject (readonly)

Returns the value of attribute version.



3
4
5
# File 'lib/gamefaqs/faq.rb', line 3

def version
  @version
end

Instance Method Details

#homepage(refresh = false) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/gamefaqs/faq.rb', line 10

def homepage(refresh=false)
  cached_value("review-#{@id}-#{@game}", [], refresh) do |homepage|
    url = "#{@game.homepage.gsub(/game/, 'file').gsub('.html', '')}/#{@id}"
    doc = Hpricot(open(url))
    doc.search("a[text()='View/Download Original File'") do |a|
      puts a.inner_html
      puts a['href']
      homepage << a['href']
    end
  end.first      
end