Class: CDB::Series
Constant Summary collapse
- FORM_SEARCHTYPE =
'Title'
- WEB_PATH =
'title.php'
Instance Attribute Summary collapse
-
#cdb_id ⇒ Object
Returns the value of attribute cdb_id.
-
#country ⇒ Object
Returns the value of attribute country.
-
#end_date ⇒ Object
Returns the value of attribute end_date.
-
#imprint ⇒ Object
Returns the value of attribute imprint.
-
#issues ⇒ Object
Returns the value of attribute issues.
-
#language ⇒ Object
Returns the value of attribute language.
-
#name ⇒ Object
Returns the value of attribute name.
-
#publisher ⇒ Object
Returns the value of attribute publisher.
-
#start_date ⇒ Object
Returns the value of attribute start_date.
Class Method Summary collapse
- .parse_data(id, page) ⇒ Object
- .parse_results(node) ⇒ Object
- .search(query) ⇒ Object
- .show(id) ⇒ Object
Methods inherited from Struct
#as_json, #initialize, #to_json
Constructor Details
This class inherits a constructor from CDB::Struct
Instance Attribute Details
#cdb_id ⇒ Object
Returns the value of attribute cdb_id
2 3 4 |
# File 'lib/cdb/series.rb', line 2 def cdb_id @cdb_id end |
#country ⇒ Object
Returns the value of attribute country
2 3 4 |
# File 'lib/cdb/series.rb', line 2 def country @country end |
#end_date ⇒ Object
Returns the value of attribute end_date
2 3 4 |
# File 'lib/cdb/series.rb', line 2 def end_date @end_date end |
#imprint ⇒ Object
Returns the value of attribute imprint
2 3 4 |
# File 'lib/cdb/series.rb', line 2 def imprint @imprint end |
#issues ⇒ Object
Returns the value of attribute issues
2 3 4 |
# File 'lib/cdb/series.rb', line 2 def issues @issues end |
#language ⇒ Object
Returns the value of attribute language
2 3 4 |
# File 'lib/cdb/series.rb', line 2 def language @language end |
#name ⇒ Object
Returns the value of attribute name
2 3 4 |
# File 'lib/cdb/series.rb', line 2 def name @name end |
#publisher ⇒ Object
Returns the value of attribute publisher
2 3 4 |
# File 'lib/cdb/series.rb', line 2 def publisher @publisher end |
#start_date ⇒ Object
Returns the value of attribute 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 |