Sha256: 5847e1ceef59f164879a04a0938d2911ae59b031a88fa7593d51f96263681f55
Contents?: true
Size: 1.62 KB
Versions: 9
Compression:
Stored size: 1.62 KB
Contents
# -*- encoding: utf-8 -*- class CiniiBook attr_reader :title, :creator, :publisher, :link, :ncid, :issued def initialize(node) @node = node end def title @node.at('./xmlns:title').try(:content) end def creator @node.at('./dc:creator').try(:content) end def publisher @node.at('./dc:publisher').try(:content) end def link @node.at('./xmlns:link').try(:content) end def ncid url = @node.attributes['about'].try(:content) if url URI.parse(url).path.split('/').reverse.first end end def issued @node.at('./dc:date').try(:content) end def self.per_page 10 end 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 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 = "http://ci.nii.ac.jp/ncid/#{ncid}.rdf" doc = Nokogiri::XML(Faraday.get(url).body) Manifestation.import_record_from_cinii_books(doc) end attr_accessor :url class AlreadyImported < StandardError end end
Version data entries
9 entries across 9 versions & 1 rubygems