Module: Bolognese::Readers::NpmReader
- Included in:
- MetadataUtils
- Defined in:
- lib/bolognese/readers/npm_reader.rb
Instance Method Summary collapse
Instance Method Details
#get_npm(id: nil, **options) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/bolognese/readers/npm_reader.rb', line 6 def get_npm(id: nil, **) return { "string" => nil, "state" => "not_found" } unless id.present? id = normalize_id(id) response = Maremma.get(id, accept: "json", raw: true) string = response.body.fetch("data", nil) { "string" => string } end |
#read_npm(string: nil, **options) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/bolognese/readers/npm_reader.rb', line 15 def read_npm(string: nil, **) if string.present? errors = jsonlint(string) return { "errors" => errors } if errors.present? end = ActiveSupport::HashWithIndifferentAccess.new(.except(:doi, :id, :url, :sandbox, :validate, :ra)) = string.present? ? Maremma.from_json(string) : {} types = { "resourceTypeGeneral" => "Software", "reourceType" => "NPM Package", "schemaOrg" => "SoftwareSourceCode", "citeproc" => "article", "bibtex" => "misc", "ris" => "GEN" }.compact creators = if .fetch("author", nil).present? (Array.wrap(.fetch("author", nil))) else [{ "nameType" => "Organizational", "name" => ":(unav)" }] end # contributors = get_authors(from_citeproc(Array.wrap(meta.fetch("editor", nil)))) # dates = if date = get_date_from_date_parts(meta.fetch("issued", nil)) # if Date.edtf(date).present? # [{ "date" => date, # "dateType" => "Issued" }] # end # end # publication_year = get_date_from_date_parts(meta.fetch("issued", nil)).to_s[0..3] rights_list = if .fetch("license", nil) [{ "rights" => .fetch("license") }.compact] end # related_identifiers = if meta.fetch("container-title", nil).present? && meta.fetch("ISSN", nil).present? # [{ "type" => "Periodical", # "relationType" => "IsPartOf", # "relatedIdentifierType" => "ISSN", # "title" => meta.fetch("container-title", nil), # "relatedIdentifier" => meta.fetch("ISSN", nil) }.compact] # end # container = if meta.fetch("container-title", nil).present? # first_page = meta.fetch("page", nil).present? ? meta.fetch("page").split("-").map(&:strip)[0] : nil # last_page = meta.fetch("page", nil).present? ? meta.fetch("page").split("-").map(&:strip)[1] : nil # { "type" => "Periodical", # "title" => meta.fetch("container-title", nil), # "identifier" => meta.fetch("ISSN", nil), # "identifierType" => meta.fetch("ISSN", nil).present? ? "ISSN" : nil, # "volume" => meta.fetch("volume", nil), # "issue" => meta.fetch("issue", nil), # "firstPage" => first_page, # "lastPage" => last_page # }.compact # else # nil # end # identifiers = [normalize_id(meta.fetch("id", nil)), normalize_doi(meta.fetch("DOI", nil))].compact.map do |r| # r = normalize_id(r) # if r.start_with?("https://doi.org") # { "identifierType" => "DOI", "identifier" => r } # else # { "identifierType" => "URL", "identifier" => r } # end # end.uniq # id = Array.wrap(identifiers).first.to_h.fetch("identifier", nil) # doi = Array.wrap(identifiers).find { |r| r["identifierType"] == "DOI" }.to_h.fetch("identifier", nil) # state = id.present? || read_options.present? ? "findable" : "not_found" subjects = Array.wrap(.fetch("keywords", nil)).map do |s| { "subject" => s } end { #"id" => id, #"identifiers" => identifiers, "types" => types, #"doi" => doi_from_url(doi), #"url" => normalize_id(meta.fetch("URL", nil)), "titles" => [{ "title" => .fetch("name", nil) }], "creators" => creators, #"contributors" => contributors, #"container" => container, #"publisher" => meta.fetch("publisher", nil), #"related_identifiers" => related_identifiers, #"dates" => dates, #"publication_year" => publication_year, "descriptions" => .fetch("description", nil).present? ? [{ "description" => sanitize(.fetch("description"), new_line: true), "descriptionType" => "Abstract" }] : [], "rights_list" => rights_list, "version_info" => .fetch("version", nil), "subjects" => subjects #"state" => state }.merge() end |