Class: NdlBook

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

Defined Under Namespace

Classes: AlreadyImported

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ NdlBook

Returns a new instance of NdlBook.



5
6
7
# File 'app/models/ndl_book.rb', line 5

def initialize(node)
  @node = node
end

Instance Attribute Details

#creatorObject (readonly)

Returns the value of attribute creator.



2
3
4
# File 'app/models/ndl_book.rb', line 2

def creator
  @creator
end

#isbnObject (readonly)

Returns the value of attribute isbn.



2
3
4
# File 'app/models/ndl_book.rb', line 2

def isbn
  @isbn
end

#issuedObject (readonly)

Returns the value of attribute issued.



2
3
4
# File 'app/models/ndl_book.rb', line 2

def issued
  @issued
end

#itemnoObject (readonly)

Returns the value of attribute itemno.



2
3
4
# File 'app/models/ndl_book.rb', line 2

def itemno
  @itemno
end

#jpnoObject (readonly)

Returns the value of attribute jpno.



2
3
4
# File 'app/models/ndl_book.rb', line 2

def jpno
  @jpno
end

Returns the value of attribute permalink.



2
3
4
# File 'app/models/ndl_book.rb', line 2

def permalink
  @permalink
end

#publisherObject (readonly)

Returns the value of attribute publisher.



2
3
4
# File 'app/models/ndl_book.rb', line 2

def publisher
  @publisher
end

#titleObject (readonly)

Returns the value of attribute title.



2
3
4
# File 'app/models/ndl_book.rb', line 2

def title
  @title
end

#urlObject

Returns the value of attribute url.



88
89
90
# File 'app/models/ndl_book.rb', line 88

def url
  @url
end

Class Method Details

.import_from_sru_response(itemno) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
# File 'app/models/ndl_book.rb', line 68

def self.import_from_sru_response(itemno)
  identifier_type = IdentifierType.find_by(name: 'iss_itemno')
  identifier_type ||= IdentifierType.create!(name: 'iss_itemno')
  identifier = Identifier.find_by(body: itemno, identifier_type_id: identifier_type.id)
  return if identifier
  url = "https://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_pageObject



49
50
51
# File 'app/models/ndl_book.rb', line 49

def self.per_page
  10
end

.search(query, page = 1, _per_page = per_page) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/models/ndl_book.rb', line 53

def self.search(query, page = 1, _per_page = per_page)
  if query
    cnt = 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| 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

#authorsObject



84
85
86
# File 'app/models/ndl_book.rb', line 84

def authors
  @node.xpath('//dcterms:creator/foaf:Agent').map{|a| {id: a.attributes['about'].content, name: a.at('./foaf:name').content, transcription: a.at('./dcndl:transcription').try(:content)}}
end

#series_titleObject



29
30
31
# File 'app/models/ndl_book.rb', line 29

def series_title
  @node.at('./dcndl:seriesTitle').try(:content).to_s
end

#subjectsObject



80
81
82
# File 'app/models/ndl_book.rb', line 80

def subjects
  @node.xpath('//dcterms:subject/rdf:Description').map{|a| {id: a.attributes['about'].content, value: a.at('./rdf:value').content}}
end

#volumeObject



25
26
27
# File 'app/models/ndl_book.rb', line 25

def volume
  @node.at('./dcndl:volume').try(:content).to_s
end