Class: CDB::Series

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

Constant Summary collapse

FORM_SEARCHTYPE =
'Title'
WEB_PATH =
'title.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/series.rb', line 2

def cdb_id
  @cdb_id
end

#countryObject

Returns the value of attribute country

Returns:

  • (Object)

    the current value of country



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

def country
  @country
end

#end_dateObject

Returns the value of attribute end_date

Returns:

  • (Object)

    the current value of end_date



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

def end_date
  @end_date
end

#imprintObject

Returns the value of attribute imprint

Returns:

  • (Object)

    the current value of imprint



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

def imprint
  @imprint
end

#issuesObject

Returns the value of attribute issues

Returns:

  • (Object)

    the current value of issues



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

def issues
  @issues
end

#languageObject

Returns the value of attribute language

Returns:

  • (Object)

    the current value of language



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

def language
  @language
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



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

def name
  @name
end

#publisherObject

Returns the value of attribute publisher

Returns:

  • (Object)

    the current value of publisher



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

def publisher
  @publisher
end

#start_dateObject

Returns the value of attribute start_date

Returns:

  • (Object)

    the current value of start_date



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

def start_date
  @start_date
end

Class Method Details

.parse_data(id, page) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cdb/series.rb', line 28

def parse_data(id, page)
  dates = page.css('strong:contains("Publication Date: ")').first.next_sibling.text.strip
  start_d, end_d = dates.split('-').map(&:strip)

  series = new(
    :cdb_id => id.to_i,
    :name => page.css('.page_headline').first.text.strip,
    :publisher => page.css('a[href^="publisher.php"]').first.text.strip,
    :imprint => (page.css('a[href^="imprint.php"]').first.text.strip rescue nil),
    :start_date => start_d,
    :end_date => end_d,
    :country => page.css('strong:contains("Country: ")').first.next_sibling.text.strip,
    :language => page.css('strong:contains("Language: ")').first.next_sibling.text.strip
  )
  series.issues = page.css("a.page_link[href^=\"#{CDB::Issue::WEB_PATH}\"]").map do |link|
    tr = link.parent.parent
    CDB::Issue.from_tr(tr, series)
  end
  series
end

.parse_results(node) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/cdb/series.rb', line 17

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
    name = text.slice(0..-8)
    year = text.slice(-5..-2)
    pub = link.next_sibling.text.gsub(/^\s*\(|\)\s*$/, '')
    new(:cdb_id => id, :name => name, :publisher => pub, :start_date => year)
  end.sort_by(&:cdb_id)
end

.search(query) ⇒ Object



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

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

.show(id) ⇒ Object



13
14
15
# File 'lib/cdb/series.rb', line 13

def show(id)
  CDB.show(id, self)
end