Class: CiniiBook

Inherits:
Object
  • Object
show all
Defined in:
app/models/cinii_book.rb

Defined Under Namespace

Classes: AlreadyImported

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#creatorObject (readonly)

Returns the value of attribute creator.



3
4
5
# File 'app/models/cinii_book.rb', line 3

def creator
  @creator
end

#issuedObject (readonly)

Returns the value of attribute issued.



3
4
5
# File 'app/models/cinii_book.rb', line 3

def issued
  @issued
end

Returns the value of attribute link.



3
4
5
# File 'app/models/cinii_book.rb', line 3

def link
  @link
end

#ncidObject (readonly)

Returns the value of attribute ncid.



3
4
5
# File 'app/models/cinii_book.rb', line 3

def ncid
  @ncid
end

#publisherObject (readonly)

Returns the value of attribute publisher.



3
4
5
# File 'app/models/cinii_book.rb', line 3

def publisher
  @publisher
end

#titleObject (readonly)

Returns the value of attribute title.



3
4
5
# File 'app/models/cinii_book.rb', line 3

def title
  @title
end

#urlObject

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_pageObject



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