Class: CDB::Issue

Inherits:
Struct
  • Object
show all
Defined in:
lib/cdb/issue.rb

Constant Summary collapse

FORM_SEARCHTYPE =
'IssueName'
WEB_PATH =
'issue.php'

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Struct

#as_json, #initialize, #to_json

Constructor Details

This class inherits a constructor from CDB::Struct

Instance Attribute Details

#cdb_idObject

Returns the value of attribute cdb_id

Returns:

  • (Object)

    the current value of cdb_id



2
3
4
# File 'lib/cdb/issue.rb', line 2

def cdb_id
  @cdb_id
end

#cover_dateObject

Returns the value of attribute cover_date

Returns:

  • (Object)

    the current value of cover_date



2
3
4
# File 'lib/cdb/issue.rb', line 2

def cover_date
  @cover_date
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



2
3
4
# File 'lib/cdb/issue.rb', line 2

def name
  @name
end

#numObject

Returns the value of attribute num

Returns:

  • (Object)

    the current value of num



2
3
4
# File 'lib/cdb/issue.rb', line 2

def num
  @num
end

#seriesObject

Returns the value of attribute series

Returns:

  • (Object)

    the current value of series



2
3
4
# File 'lib/cdb/issue.rb', line 2

def series
  @series
end

#story_arcObject

Returns the value of attribute story_arc

Returns:

  • (Object)

    the current value of story_arc



2
3
4
# File 'lib/cdb/issue.rb', line 2

def story_arc
  @story_arc
end

Class Method Details

.from_tr(node, series) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/cdb/issue.rb', line 25

def from_tr(node, series)
  tds = node.css('td')
  link = tds[0].css("a[href^=\"#{WEB_PATH}\"]").first
  new(:cdb_id => link['href'].split('=').last.strip.to_i,
      :series => series,
      :num => link.text.strip,
      :name => tds[2].text.strip,
      :story_arc => tds[4].text.strip,
      :cover_date => tds[6].text.strip)
end

.parse_results(node) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cdb/issue.rb', line 13

def parse_results(node)
  node.css("a[href^=\"#{WEB_PATH}\"]").map do |link|
    id = link.attr('href').split('=').last.to_i
    text = link.child.text.strip
    match = text.match(/^(.* \(\d{4}\)) (.*)$/)
    series = match[1]
    num = match[2].gsub(/^#/, '')
    name = link.next_sibling.text.strip.gsub(/^-\s*"|"$/, '').strip
    new(:cdb_id => id, :series => series, :num => num, :name => name)
  end.sort_by(&:cdb_id)
end

.search(query) ⇒ Object



8
9
10
11
# File 'lib/cdb/issue.rb', line 8

def search(query)
  results = CDB.search(query, FORM_SEARCHTYPE)
  results[:issues]
end