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

#descriptionObject



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

def description
  info[0].text 
end

#genresObject



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

def genres
  info[14].css('a')[0..-2].map {|a| a.text}
end

#idObject



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

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

#infoObject



29
30
31
# File 'lib/bu/dashboard.rb', line 29

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

#scanlatorsObject



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

#titleObject



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

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

#to_hObject



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_sObject



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