Class: BU::Dashboard
- Inherits:
-
Object
- Object
- BU::Dashboard
- Defined in:
- lib/bu/dashboard.rb
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #artists ⇒ Object
- #authors ⇒ Object
- #description ⇒ Object
- #genres ⇒ Object
- #id ⇒ Object
- #info ⇒ Object
-
#initialize(url, doc) ⇒ Dashboard
constructor
A new instance of Dashboard.
- #scanlators ⇒ Object
- #title ⇒ Object
- #to_h ⇒ Object (also: #to_hash)
- #to_s ⇒ Object
Constructor Details
#initialize(url, doc) ⇒ Dashboard
Returns a new instance of Dashboard.
5 6 7 8 |
# File 'lib/bu/dashboard.rb', line 5 def initialize(url, doc) @url = url @doc = doc end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
4 5 6 |
# File 'lib/bu/dashboard.rb', line 4 def doc @doc end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
4 5 6 |
# File 'lib/bu/dashboard.rb', line 4 def url @url end |
Instance Method Details
#artists ⇒ Object
56 57 58 |
# File 'lib/bu/dashboard.rb', line 56 def artists info[19].css('a').map(&:text) end |
#authors ⇒ Object
52 53 54 |
# File 'lib/bu/dashboard.rb', line 52 def info[18].css('a').map(&:text) end |
#description ⇒ Object
44 45 46 |
# File 'lib/bu/dashboard.rb', line 44 def description info[0].text end |
#genres ⇒ Object
48 49 50 |
# File 'lib/bu/dashboard.rb', line 48 def genres info[14].css('a')[0..-2].map(&:text) end |
#id ⇒ Object
40 41 42 |
# File 'lib/bu/dashboard.rb', line 40 def id Integer(url.sub(/.+id=/, '')) end |
#info ⇒ Object
32 33 34 |
# File 'lib/bu/dashboard.rb', line 32 def info @info ||= doc.css('.sMember div.sContent') end |
#scanlators ⇒ Object
59 60 61 62 63 |
# File 'lib/bu/dashboard.rb', line 59 def scanlators info[4].css('a') .select {|a| a.text != "Less..." && a.text != "More..." } .map {|a| {url: a[:href], name: a.text} } end |
#title ⇒ Object
36 37 38 |
# File 'lib/bu/dashboard.rb', line 36 def title @doc.css('span.releasestitle.tabletitle').first.text end |
#to_h ⇒ Object Also known as: to_hash
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/bu/dashboard.rb', line 10 def to_h { url: url, title: title, id: id, genres: genres, authors: , artists: artists, description: description, scanlators: scanlators, } end |
#to_s ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/bu/dashboard.rb', line 24 def to_s to_h.each_with_object('') do |(key,value),out| column = key.to_s.upcase spaces = 13 - column.length out << "\s\s#{column}:#{ " " * spaces}#{value}\n" end end |