Sha256: f3ee00a3166adad9ef532817747dcc0784072b32075e60b6008001fec6751819

Contents?: true

Size: 1005 Bytes

Versions: 1

Compression:

Stored size: 1005 Bytes

Contents

require 'open-uri'
require 'json'
require 'date'

module Sist02
  module CiNii
    module_function
    def article_ref(naid)
      begin
        html = open("http://ci.nii.ac.jp/naid/#{naid}.json").read
        json = JSON.parser.new(html)
        hash = json.parse["@graph"][0]
        title =  hash["dc:title"][0]["@value"]
        creator_raw = hash["dc:creator"]
        creator = ''
        creator_raw.each do |item|
          creator += "#{item[0]["@value"]}, "
        end
        creator = creator.gsub(/\,\s$/, '')
        publication_name = hash["prism:publicationName"][0]["@value"]
        year = hash["dc:date"].match(/\d{4}/)
        volume = hash["prism:volume"]
        number = hash["prism:number"]
        start_p = hash["prism:startingPage"]
        end_p = hash["prism:endingPage"]
        result = "#{creator}. #{title}. #{publication_name}. #{year}, #{volume}(#{number}), p. #{start_p}-#{end_p}."
      rescue => e
        result = e
      end
      return result
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sist02-0.1.4 lib/sist02/cinii.rb