Module: Bolognese::Readers::CodemetaReader

Included in:
Metadata
Defined in:
lib/bolognese/readers/codemeta_reader.rb

Instance Method Summary collapse

Instance Method Details

#get_codemeta(id: nil) ⇒ Object



4
5
6
7
8
9
# File 'lib/bolognese/readers/codemeta_reader.rb', line 4

def get_codemeta(id: nil)
  return nil unless id.present?
  id = normalize_id(id)
  response = Maremma.get(github_as_codemeta_url(id), accept: "json", raw: true)
  response.body.fetch("data", nil)
end

#read_codemeta(string: nil) ⇒ Object



11
12
13
14
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
# File 'lib/bolognese/readers/codemeta_reader.rb', line 11

def read_codemeta(string: nil)
  errors = jsonlint(string)
  return { "errors" => errors } if errors.present?

  meta = string.present? ? Maremma.from_json(string) : {}
  identifier = meta.fetch("identifier", nil)
  id = normalize_id(meta.fetch("@id", nil) || identifier)
  type = meta.fetch("@type", nil)
  author = get_authors(from_schema_org(Array.wrap(meta.fetch("agents", nil))))
  editor = get_authors(from_schema_org(Array.wrap(meta.fetch("editor", nil))))
  date_published = meta.fetch("datePublished", nil)
  publisher = meta.fetch("publisher", nil)

  { "id" => id,
    "type" => type,
    "additional_type" => meta.fetch("additionalType", nil),
    "citeproc_type" => Bolognese::Utils::SO_TO_CP_TRANSLATIONS[type] || "article-journal",
    "bibtex_type" => Bolognese::Utils::SO_TO_BIB_TRANSLATIONS[type] || "misc",
    "ris_type" => Bolognese::Utils::SO_TO_RIS_TRANSLATIONS[type] || "GEN",
    "resource_type_general" => Bolognese::Utils::SO_TO_DC_TRANSLATIONS[type],
    "identifier" => identifier,
    "doi" => validate_doi(id),
    "url" => normalize_id(meta.fetch("codeRepository", nil)),
    "title" => meta.fetch("title", nil),
    "alternate_name" => meta.fetch("alternateName", nil),
    "author" => author,
    "editor" => editor,
    "publisher" => publisher,
    #{}"is_part_of" => is_part_of,
    "date_created" => meta.fetch("dateCreated", nil),
    "date_published" => date_published,
    "date_modified" => meta.fetch("dateModified", nil),
    "description" => meta.fetch("description", nil).present? ? { "text" => sanitize(meta.fetch("description")) } : nil,
    "license" => { "id" => meta.fetch("license", nil) },
    "version" => meta.fetch("version", nil),
    "keywords" => meta.fetch("tags", nil)
  }
end