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
- #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
- #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
#description ⇒ Object
41 42 43 |
# File 'lib/bu/dashboard.rb', line 41 def description info[0].text end |
#genres ⇒ Object
45 46 47 |
# File 'lib/bu/dashboard.rb', line 45 def genres info[14].css('a')[0..-2].map {|a| a.text} end |
#id ⇒ Object
37 38 39 |
# File 'lib/bu/dashboard.rb', line 37 def id Integer(url.sub(/.+id=/, '')) end |
#info ⇒ Object
29 30 31 |
# File 'lib/bu/dashboard.rb', line 29 def info @info ||= doc.css('.sMember div.sContent') end |
#scanlators ⇒ Object
49 50 51 52 53 |
# File 'lib/bu/dashboard.rb', line 49 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
33 34 35 |
# File 'lib/bu/dashboard.rb', line 33 def title @doc.css('span.releasestitle.tabletitle').first.text end |
#to_h ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/bu/dashboard.rb', line 10 def to_h { url: url, title: title, id: id, genres: genres, description: description, scanlators: scanlators, } end |
#to_s ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/bu/dashboard.rb', line 21 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 |