Class: Skooby::Book

Inherits:
Object
  • Object
show all
Defined in:
lib/skooby/book.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Book

Returns a new instance of Book.



7
8
9
10
11
12
13
# File 'lib/skooby/book.rb', line 7

def initialize(params = {})
  @id     = params[:id]     if params.has_key?(:id)
  @title  = params[:title]  if params.has_key?(:title)
  @author = params[:author] if params.has_key?(:author)
  @rating = params[:rating] if params.has_key?(:rating)
  @votes  = params[:votes]  if params.has_key?(:votes)
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



5
6
7
# File 'lib/skooby/book.rb', line 5

def author
  @author
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/skooby/book.rb', line 5

def id
  @id
end

#ratingObject (readonly)

Returns the value of attribute rating.



5
6
7
# File 'lib/skooby/book.rb', line 5

def rating
  @rating
end

#titleObject (readonly)

Returns the value of attribute title.



5
6
7
# File 'lib/skooby/book.rb', line 5

def title
  @title
end

#votesObject (readonly)

Returns the value of attribute votes.



5
6
7
# File 'lib/skooby/book.rb', line 5

def votes
  @votes
end

Instance Method Details

#fetchObject



31
32
33
34
35
36
37
38
# File 'lib/skooby/book.rb', line 31

def fetch
  doc = Nokogiri::HTML.parse(Request.new.get(path))
  @title  = doc.css('#barra_titulo h1')[0].content
  @author = doc.css('.l11')[0].content
  @rating = (doc.css('#bt_ranking')[0].content.to_f / 5).round(2)
  @votes  = /(\d+)/.match(doc.css('#bt_estrelas')[0].content)[1]
  self
end

#urlObject



15
16
17
# File 'lib/skooby/book.rb', line 15

def url
  Skooby::Request.base_uri + path
end