Class: CiniiBook
- Inherits:
-
Object
- Object
- CiniiBook
- Defined in:
- app/models/cinii_book.rb
Defined Under Namespace
Classes: AlreadyImported
Instance Attribute Summary collapse
-
#creator ⇒ Object
readonly
Returns the value of attribute creator.
-
#issued ⇒ Object
readonly
Returns the value of attribute issued.
-
#link ⇒ Object
readonly
Returns the value of attribute link.
-
#ncid ⇒ Object
readonly
Returns the value of attribute ncid.
-
#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_ncid(ncid) ⇒ Object
- .per_page ⇒ Object
- .search(query, page = 1, per_page = self.per_page) ⇒ Object
Instance Method Summary collapse
-
#initialize(node) ⇒ CiniiBook
constructor
A new instance of CiniiBook.
Constructor Details
#initialize(node) ⇒ CiniiBook
Returns a new instance of CiniiBook.
5 6 7 |
# File 'app/models/cinii_book.rb', line 5 def initialize(node) @node = node end |
Instance Attribute Details
#creator ⇒ Object (readonly)
Returns the value of attribute creator.
3 4 5 |
# File 'app/models/cinii_book.rb', line 3 def creator @creator end |
#issued ⇒ Object (readonly)
Returns the value of attribute issued.
3 4 5 |
# File 'app/models/cinii_book.rb', line 3 def issued @issued end |
#link ⇒ Object (readonly)
Returns the value of attribute link.
3 4 5 |
# File 'app/models/cinii_book.rb', line 3 def link @link end |
#ncid ⇒ Object (readonly)
Returns the value of attribute ncid.
3 4 5 |
# File 'app/models/cinii_book.rb', line 3 def ncid @ncid end |
#publisher ⇒ Object (readonly)
Returns the value of attribute publisher.
3 4 5 |
# File 'app/models/cinii_book.rb', line 3 def publisher @publisher end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
3 4 5 |
# File 'app/models/cinii_book.rb', line 3 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
64 65 66 |
# File 'app/models/cinii_book.rb', line 64 def url @url end |
Class Method Details
.import_ncid(ncid) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'app/models/cinii_book.rb', line 54 def self.import_ncid(ncid) identifier_type = IdentifierType.where(name: 'ncid').first identifier_type = IdentifierType.create!(name: 'ncid') unless identifier_type identifier = Identifier.where(body: ncid, identifier_type_id: identifier_type.id).first return if identifier url = "https://ci.nii.ac.jp/ncid/#{ncid}.rdf" doc = Nokogiri::XML(Faraday.get(url).body) Manifestation.import_record_from_cinii_books(doc) end |
.per_page ⇒ Object
36 37 38 |
# File 'app/models/cinii_book.rb', line 36 def self.per_page 10 end |
.search(query, page = 1, per_page = self.per_page) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/models/cinii_book.rb', line 40 def self.search(query, page = 1, per_page = self.per_page) if query cnt = self.per_page page = 1 if page.to_i < 1 doc = Nokogiri::XML(Manifestation.search_cinii_book(query, {p: page, count: cnt, raw: true}).to_s) items = doc.xpath('//xmlns:item').collect{|node| self.new node } total_entries = doc.at('//opensearch:totalResults').content.to_i {items: items, total_entries: total_entries} else {items: [], total_entries: 0} end end |