Class: NdlBook
- Inherits:
-
Object
- Object
- NdlBook
- Defined in:
- app/models/ndl_book.rb
Defined Under Namespace
Classes: AlreadyImported
Instance Attribute Summary collapse
-
#creator ⇒ Object
readonly
Returns the value of attribute creator.
-
#isbn ⇒ Object
readonly
Returns the value of attribute isbn.
-
#issued ⇒ Object
readonly
Returns the value of attribute issued.
-
#itemno ⇒ Object
readonly
Returns the value of attribute itemno.
-
#jpno ⇒ Object
readonly
Returns the value of attribute jpno.
-
#permalink ⇒ Object
readonly
Returns the value of attribute permalink.
-
#publisher ⇒ Object
readonly
Returns the value of attribute publisher.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .import_from_sru_response(itemno) ⇒ Object
- .per_page ⇒ Object
- .search(query, page = 1, per_page = self.per_page) ⇒ Object
Instance Method Summary collapse
-
#initialize(node) ⇒ NdlBook
constructor
A new instance of NdlBook.
- #series_title ⇒ Object
- #volume ⇒ Object
Constructor Details
#initialize(node) ⇒ NdlBook
Returns a new instance of NdlBook.
6 7 8 |
# File 'app/models/ndl_book.rb', line 6 def initialize(node) @node = node end |
Instance Attribute Details
#creator ⇒ Object (readonly)
Returns the value of attribute creator.
3 4 5 |
# File 'app/models/ndl_book.rb', line 3 def creator @creator end |
#isbn ⇒ Object (readonly)
Returns the value of attribute isbn.
3 4 5 |
# File 'app/models/ndl_book.rb', line 3 def isbn @isbn end |
#issued ⇒ Object (readonly)
Returns the value of attribute issued.
3 4 5 |
# File 'app/models/ndl_book.rb', line 3 def issued @issued end |
#itemno ⇒ Object (readonly)
Returns the value of attribute itemno.
3 4 5 |
# File 'app/models/ndl_book.rb', line 3 def itemno @itemno end |
#jpno ⇒ Object (readonly)
Returns the value of attribute jpno.
3 4 5 |
# File 'app/models/ndl_book.rb', line 3 def jpno @jpno end |
#permalink ⇒ Object (readonly)
Returns the value of attribute permalink.
3 4 5 |
# File 'app/models/ndl_book.rb', line 3 def permalink @permalink end |
#publisher ⇒ Object (readonly)
Returns the value of attribute publisher.
3 4 5 |
# File 'app/models/ndl_book.rb', line 3 def publisher @publisher end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
3 4 5 |
# File 'app/models/ndl_book.rb', line 3 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
81 82 83 |
# File 'app/models/ndl_book.rb', line 81 def url @url end |
Class Method Details
.import_from_sru_response(itemno) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/models/ndl_book.rb', line 69 def self.import_from_sru_response(itemno) identifier_type = IdentifierType.where(name: 'iss_itemno').first identifier_type = IdentifierType.create!(name: 'iss_itemno') unless identifier_type identifier = Identifier.where(body: itemno, identifier_type_id: identifier_type.id).first return if identifier url = "http://iss.ndl.go.jp/api/sru?operation=searchRetrieve&recordSchema=dcndl&maximumRecords=1&query=%28itemno=#{itemno}%29&onlyBib=true" xml = Faraday.get(url).body response = Nokogiri::XML(xml).at('//xmlns:recordData') return unless response.try(:content) Manifestation.import_record(Nokogiri::XML(response.content)) end |
.per_page ⇒ Object
50 51 52 |
# File 'app/models/ndl_book.rb', line 50 def self.per_page 10 end |
.search(query, page = 1, per_page = self.per_page) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/ndl_book.rb', line 54 def self.search(query, page = 1, per_page = self.per_page) if query cnt = self.per_page page = 1 if page.to_i < 1 idx = (page.to_i - 1) * cnt + 1 doc = Nokogiri::XML(Manifestation.search_ndl(query, {cnt: cnt, page: page, idx: idx, raw: true, mediatype: 1}).to_s) items = doc.xpath('//channel/item').map{|node| self.new node } total_entries = doc.at('//channel/openSearch:totalResults').content.to_i {items: items, total_entries: total_entries} else {items: [], total_entries: 0} end end |
Instance Method Details
#series_title ⇒ Object
30 31 32 |
# File 'app/models/ndl_book.rb', line 30 def series_title @node.at('./dcndl:seriesTitle').try(:content).to_s end |
#volume ⇒ Object
26 27 28 |
# File 'app/models/ndl_book.rb', line 26 def volume @node.at('./dcndl:volume').try(:content).to_s end |