Class: Skooby::Book
- Inherits:
-
Object
- Object
- Skooby::Book
- Defined in:
- lib/skooby/book.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#rating ⇒ Object
readonly
Returns the value of attribute rating.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#votes ⇒ Object
readonly
Returns the value of attribute votes.
Instance Method Summary collapse
- #fetch ⇒ Object
-
#initialize(params = {}) ⇒ Book
constructor
A new instance of Book.
- #url ⇒ Object
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
#author ⇒ Object (readonly)
Returns the value of attribute author.
5 6 7 |
# File 'lib/skooby/book.rb', line 5 def @author end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/skooby/book.rb', line 5 def id @id end |
#rating ⇒ Object (readonly)
Returns the value of attribute rating.
5 6 7 |
# File 'lib/skooby/book.rb', line 5 def @rating end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
5 6 7 |
# File 'lib/skooby/book.rb', line 5 def title @title end |
#votes ⇒ Object (readonly)
Returns the value of attribute votes.
5 6 7 |
# File 'lib/skooby/book.rb', line 5 def votes @votes end |
Instance Method Details
#fetch ⇒ Object
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 |