Class: BU::Dashboard

Inherits:
Object
  • Object
show all
Defined in:
lib/bu/dashboard.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#docObject (readonly)

Returns the value of attribute doc.



4
5
6
# File 'lib/bu/dashboard.rb', line 4

def doc
  @doc
end

#urlObject (readonly)

Returns the value of attribute url.



4
5
6
# File 'lib/bu/dashboard.rb', line 4

def url
  @url
end

Instance Method Details

#artistsObject



56
57
58
# File 'lib/bu/dashboard.rb', line 56

def artists
  info[19].css('a').map(&:text)
end

#authorsObject



52
53
54
# File 'lib/bu/dashboard.rb', line 52

def authors
  info[18].css('a').map(&:text)
end

#descriptionObject



44
45
46
# File 'lib/bu/dashboard.rb', line 44

def description
  info[0].text 
end

#genresObject



48
49
50
# File 'lib/bu/dashboard.rb', line 48

def genres
  info[14].css('a')[0..-2].map(&:text)
end

#idObject



40
41
42
# File 'lib/bu/dashboard.rb', line 40

def id
  Integer(url.sub(/.+id=/, '')) 
end

#infoObject



32
33
34
# File 'lib/bu/dashboard.rb', line 32

def info
  @info ||= doc.css('.sMember div.sContent')
end

#scanlatorsObject



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

#titleObject



36
37
38
# File 'lib/bu/dashboard.rb', line 36

def title
  @doc.css('span.releasestitle.tabletitle').first.text
end

#to_hObject 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:     authors,
    artists:     artists,
    description: description,
    scanlators:  scanlators,
  }
end

#to_sObject



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