bolognese 0.4.3 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (326) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/build.yml +9 -0
  3. data/.github/workflows/changelog.yml +36 -0
  4. data/.github/workflows/ci.yml +22 -0
  5. data/.github/workflows/pull-request.yml +9 -0
  6. data/.github/workflows/release.yml +32 -0
  7. data/.gitignore +4 -0
  8. data/.rubocop.yml +658 -0
  9. data/CHANGELOG.md +1864 -0
  10. data/CITATION +17 -0
  11. data/Gemfile +1 -1
  12. data/Gemfile.lock +250 -98
  13. data/README.md +963 -21
  14. data/Rakefile +1 -0
  15. data/bin/bolognese +5 -1
  16. data/bolognese.gemspec +33 -21
  17. data/lib/bolognese/array.rb +13 -0
  18. data/lib/bolognese/author_utils.rb +147 -33
  19. data/lib/bolognese/citeproc_extensions.rb +48 -0
  20. data/lib/bolognese/cli.rb +28 -21
  21. data/lib/bolognese/datacite_utils.rb +292 -104
  22. data/lib/bolognese/doi_utils.rb +44 -20
  23. data/lib/bolognese/metadata.rb +249 -23
  24. data/lib/bolognese/metadata_utils.rb +228 -0
  25. data/lib/bolognese/pubmed.rb +2 -0
  26. data/lib/bolognese/readers/bibtex_reader.rb +100 -0
  27. data/lib/bolognese/readers/citeproc_reader.rb +125 -0
  28. data/lib/bolognese/readers/codemeta_reader.rb +108 -0
  29. data/lib/bolognese/readers/crosscite_reader.rb +17 -0
  30. data/lib/bolognese/readers/crossref_reader.rb +413 -0
  31. data/lib/bolognese/readers/datacite_json_reader.rb +17 -0
  32. data/lib/bolognese/readers/datacite_reader.rb +341 -0
  33. data/lib/bolognese/readers/npm_reader.rb +115 -0
  34. data/lib/bolognese/readers/ris_reader.rb +114 -0
  35. data/lib/bolognese/readers/schema_org_reader.rb +264 -0
  36. data/lib/bolognese/string.rb +3 -1
  37. data/lib/bolognese/utils.rb +1463 -25
  38. data/lib/bolognese/version.rb +1 -1
  39. data/lib/bolognese/whitelist_scrubber.rb +47 -0
  40. data/lib/bolognese/writers/bibtex_writer.rb +32 -0
  41. data/lib/bolognese/writers/citation_writer.rb +14 -0
  42. data/lib/bolognese/writers/citeproc_writer.rb +11 -0
  43. data/lib/bolognese/writers/codemeta_writer.rb +29 -0
  44. data/lib/bolognese/writers/crosscite_writer.rb +11 -0
  45. data/lib/bolognese/writers/crossref_writer.rb +11 -0
  46. data/lib/bolognese/writers/csv_writer.rb +24 -0
  47. data/lib/bolognese/writers/datacite_json_writer.rb +13 -0
  48. data/lib/bolognese/writers/datacite_writer.rb +12 -0
  49. data/lib/bolognese/writers/jats_writer.rb +137 -0
  50. data/lib/bolognese/writers/rdf_xml_writer.rb +11 -0
  51. data/lib/bolognese/writers/ris_writer.rb +29 -0
  52. data/lib/bolognese/writers/schema_org_writer.rb +55 -0
  53. data/lib/bolognese/writers/turtle_writer.rb +11 -0
  54. data/lib/bolognese.rb +19 -5
  55. data/package.json +12 -0
  56. data/resources/2008/09/xsd.xsl +997 -0
  57. data/resources/datacite-contributorType-v4.xsd +35 -0
  58. data/resources/datacite-dateType-v4.xsd +25 -0
  59. data/resources/datacite-descriptionType-v4.xsd +19 -0
  60. data/resources/datacite-funderIdentifierType-v4.xsd +15 -0
  61. data/resources/datacite-nameType-v4.xsd +10 -0
  62. data/resources/datacite-relatedIdentifierType-v4.xsd +34 -0
  63. data/resources/datacite-relationType-v4.xsd +49 -0
  64. data/resources/datacite-resourceType-v4.xsd +28 -0
  65. data/resources/datacite-titleType-v4.xsd +14 -0
  66. data/resources/kernel-2.1/include/datacite-contributorType-v1.1.xsd +22 -0
  67. data/resources/kernel-2.1/include/datacite-contributorType-v2.xsd +3 -0
  68. data/resources/kernel-2.1/include/datacite-dateType-v1.1.xsd +31 -0
  69. data/resources/kernel-2.1/include/datacite-dateType-v2.xsd +3 -0
  70. data/resources/kernel-2.1/include/datacite-descriptionType-v1.1.xsd +14 -0
  71. data/resources/kernel-2.1/include/datacite-descriptionType-v2.xsd +3 -0
  72. data/resources/kernel-2.1/include/datacite-relatedIdentifierType-v1.1.xsd +24 -0
  73. data/resources/kernel-2.1/include/datacite-relatedIdentifierType-v2.xsd +3 -0
  74. data/resources/kernel-2.1/include/datacite-relationType-v1.1.xsd +29 -0
  75. data/resources/kernel-2.1/include/datacite-relationType-v2.xsd +3 -0
  76. data/resources/kernel-2.1/include/datacite-resourceType-v1.1.xsd +22 -0
  77. data/resources/kernel-2.1/include/datacite-resourceType-v2.xsd +3 -0
  78. data/resources/kernel-2.1/include/datacite-titleType-v1.1.xsd +11 -0
  79. data/resources/kernel-2.1/include/datacite-titleType-v2.xsd +3 -0
  80. data/resources/kernel-2.1/metadata.xsd +315 -0
  81. data/resources/kernel-2.2/include/datacite-contributorType-v2.xsd +29 -0
  82. data/resources/kernel-2.2/include/datacite-dateType-v2.xsd +21 -0
  83. data/resources/kernel-2.2/include/datacite-descriptionType-v2.xsd +15 -0
  84. data/resources/kernel-2.2/include/datacite-relatedIdentifierType-v2.xsd +25 -0
  85. data/resources/kernel-2.2/include/datacite-relationType-v2.xsd +29 -0
  86. data/resources/kernel-2.2/include/datacite-resourceType-v2.xsd +23 -0
  87. data/resources/kernel-2.2/include/datacite-titleType-v2.xsd +10 -0
  88. data/resources/kernel-2.2/metadata.xsd +316 -0
  89. data/resources/kernel-3/include/datacite-contributorType-v3.1.xsd +35 -0
  90. data/resources/kernel-3/include/datacite-dateType-v3.xsd +21 -0
  91. data/resources/kernel-3/include/datacite-descriptionType-v3.xsd +17 -0
  92. data/resources/kernel-3/include/datacite-relatedIdentifierType-v3.1.xsd +30 -0
  93. data/resources/kernel-3/include/datacite-relationType-v3.1.xsd +38 -0
  94. data/resources/kernel-3/include/datacite-resourceType-v3.xsd +26 -0
  95. data/resources/kernel-3/include/datacite-titleType-v3.xsd +12 -0
  96. data/resources/kernel-3/include/xml.xsd +286 -0
  97. data/resources/kernel-3/metadata.xsd +380 -0
  98. data/resources/kernel-3.0/include/datacite-contributorType-v3.xsd +33 -0
  99. data/resources/kernel-3.0/include/datacite-dateType-v3.xsd +21 -0
  100. data/resources/kernel-3.0/include/datacite-descriptionType-v3.xsd +17 -0
  101. data/resources/kernel-3.0/include/datacite-relatedIdentifierType-v3.xsd +27 -0
  102. data/resources/kernel-3.0/include/datacite-relationType-v3.xsd +33 -0
  103. data/resources/kernel-3.0/include/datacite-resourceType-v3.xsd +26 -0
  104. data/resources/kernel-3.0/include/datacite-titleType-v3.xsd +12 -0
  105. data/resources/kernel-3.0/include/xml.xsd +286 -0
  106. data/resources/kernel-3.0/metadata.xsd +377 -0
  107. data/resources/kernel-3.1/include/datacite-contributorType-v3.1.xsd +35 -0
  108. data/resources/kernel-3.1/include/datacite-dateType-v3.xsd +21 -0
  109. data/resources/kernel-3.1/include/datacite-descriptionType-v3.xsd +17 -0
  110. data/resources/kernel-3.1/include/datacite-relatedIdentifierType-v3.1.xsd +30 -0
  111. data/resources/kernel-3.1/include/datacite-relationType-v3.1.xsd +38 -0
  112. data/resources/kernel-3.1/include/datacite-resourceType-v3.xsd +26 -0
  113. data/resources/kernel-3.1/include/datacite-titleType-v3.xsd +12 -0
  114. data/resources/kernel-3.1/include/xml.xsd +286 -0
  115. data/resources/kernel-3.1/metadata.xsd +380 -0
  116. data/resources/kernel-4/include/datacite-contributorType-v4.xsd +37 -0
  117. data/resources/kernel-4/include/datacite-dateType-v4.xsd +27 -0
  118. data/resources/kernel-4/include/datacite-descriptionType-v4.xsd +19 -0
  119. data/resources/kernel-4/include/datacite-funderIdentifierType-v4.xsd +16 -0
  120. data/resources/kernel-4/include/datacite-nameType-v4.xsd +10 -0
  121. data/resources/kernel-4/include/datacite-numberType-v4.xsd +12 -0
  122. data/resources/kernel-4/include/datacite-relatedIdentifierType-v4.xsd +39 -0
  123. data/resources/kernel-4/include/datacite-relationType-v4.xsd +59 -0
  124. data/resources/kernel-4/include/datacite-resourceType-v4.xsd +52 -0
  125. data/resources/kernel-4/include/datacite-titleType-v4.xsd +14 -0
  126. data/resources/kernel-4/include/xml.xsd +286 -0
  127. data/resources/kernel-4/metadata.xsd +715 -0
  128. data/resources/kernel-4.0/include/datacite-contributorType-v4.xsd +1 -1
  129. data/resources/kernel-4.0/include/datacite-dateType-v4.xsd +1 -1
  130. data/resources/kernel-4.0/include/datacite-descriptionType-v4.xsd +1 -1
  131. data/resources/kernel-4.0/include/datacite-funderIdentifierType-v4.xsd +1 -1
  132. data/resources/kernel-4.0/include/datacite-relatedIdentifierType-v4.xsd +1 -1
  133. data/resources/kernel-4.0/include/datacite-relationType-v4.xsd +1 -1
  134. data/resources/kernel-4.0/include/datacite-resourceType-v4.xsd +1 -1
  135. data/resources/kernel-4.0/include/datacite-titleType-v4.xsd +1 -1
  136. data/resources/kernel-4.0/include/xml.xsd +286 -0
  137. data/resources/kernel-4.0/metadata.xsd +2 -2
  138. data/resources/kernel-4.1/include/datacite-contributorType-v4.xsd +35 -0
  139. data/resources/kernel-4.1/include/datacite-dateType-v4.1.xsd +23 -0
  140. data/resources/kernel-4.1/include/datacite-descriptionType-v4.xsd +19 -0
  141. data/resources/kernel-4.1/include/datacite-funderIdentifierType-v4.xsd +15 -0
  142. data/resources/kernel-4.1/include/datacite-nameType-v4.1.xsd +10 -0
  143. data/resources/kernel-4.1/include/datacite-relatedIdentifierType-v4.xsd +32 -0
  144. data/resources/kernel-4.1/include/datacite-relationType-v4.1.xsd +46 -0
  145. data/resources/kernel-4.1/include/datacite-resourceType-v4.1.xsd +28 -0
  146. data/resources/kernel-4.1/include/datacite-titleType-v4.xsd +14 -0
  147. data/resources/kernel-4.1/include/xml.xsd +286 -0
  148. data/resources/kernel-4.1/metadata.xsd +483 -0
  149. data/resources/kernel-4.2/include/datacite-contributorType-v4.xsd +35 -0
  150. data/resources/kernel-4.2/include/datacite-dateType-v4.xsd +25 -0
  151. data/resources/kernel-4.2/include/datacite-descriptionType-v4.xsd +19 -0
  152. data/resources/kernel-4.2/include/datacite-funderIdentifierType-v4.xsd +15 -0
  153. data/resources/kernel-4.2/include/datacite-nameType-v4.xsd +10 -0
  154. data/resources/kernel-4.2/include/datacite-relatedIdentifierType-v4.xsd +34 -0
  155. data/resources/kernel-4.2/include/datacite-relationType-v4.xsd +49 -0
  156. data/resources/kernel-4.2/include/datacite-resourceType-v4.xsd +28 -0
  157. data/resources/kernel-4.2/include/datacite-titleType-v4.xsd +14 -0
  158. data/resources/kernel-4.2/include/xml.xsd +286 -0
  159. data/resources/kernel-4.2/metadata.xsd +479 -0
  160. data/resources/kernel-4.3/include/datacite-contributorType-v4.xsd +35 -0
  161. data/resources/kernel-4.3/include/datacite-dateType-v4.xsd +25 -0
  162. data/resources/kernel-4.3/include/datacite-descriptionType-v4.xsd +19 -0
  163. data/resources/kernel-4.3/include/datacite-funderIdentifierType-v4.xsd +16 -0
  164. data/resources/kernel-4.3/include/datacite-nameType-v4.xsd +10 -0
  165. data/resources/kernel-4.3/include/datacite-relatedIdentifierType-v4.xsd +34 -0
  166. data/resources/kernel-4.3/include/datacite-relationType-v4.xsd +49 -0
  167. data/resources/kernel-4.3/include/datacite-resourceType-v4.xsd +28 -0
  168. data/resources/kernel-4.3/include/datacite-titleType-v4.xsd +14 -0
  169. data/resources/kernel-4.3/include/xml.xsd +286 -0
  170. data/resources/kernel-4.3/metadata.xsd +515 -0
  171. data/resources/kernel-4.4/include/datacite-contributorType-v4.xsd +35 -0
  172. data/resources/kernel-4.4/include/datacite-dateType-v4.xsd +25 -0
  173. data/resources/kernel-4.4/include/datacite-descriptionType-v4.xsd +19 -0
  174. data/resources/kernel-4.4/include/datacite-funderIdentifierType-v4.xsd +16 -0
  175. data/resources/kernel-4.4/include/datacite-nameType-v4.xsd +10 -0
  176. data/resources/kernel-4.4/include/datacite-numberType-v4.xsd +12 -0
  177. data/resources/kernel-4.4/include/datacite-relatedIdentifierType-v4.xsd +34 -0
  178. data/resources/kernel-4.4/include/datacite-relationType-v4.xsd +51 -0
  179. data/resources/kernel-4.4/include/datacite-resourceType-v4.xsd +43 -0
  180. data/resources/kernel-4.4/include/datacite-titleType-v4.xsd +14 -0
  181. data/resources/kernel-4.4/include/xml.xsd +286 -0
  182. data/resources/kernel-4.4/metadata.xsd +707 -0
  183. data/resources/kernel-4.5/include/datacite-contributorType-v4.xsd +35 -0
  184. data/resources/kernel-4.5/include/datacite-dateType-v4.xsd +25 -0
  185. data/resources/kernel-4.5/include/datacite-descriptionType-v4.xsd +19 -0
  186. data/resources/kernel-4.5/include/datacite-funderIdentifierType-v4.xsd +16 -0
  187. data/resources/kernel-4.5/include/datacite-nameType-v4.xsd +10 -0
  188. data/resources/kernel-4.5/include/datacite-numberType-v4.xsd +12 -0
  189. data/resources/kernel-4.5/include/datacite-relatedIdentifierType-v4.xsd +34 -0
  190. data/resources/kernel-4.5/include/datacite-relationType-v4.xsd +53 -0
  191. data/resources/kernel-4.5/include/datacite-resourceType-v4.xsd +45 -0
  192. data/resources/kernel-4.5/include/datacite-titleType-v4.xsd +14 -0
  193. data/resources/kernel-4.5/include/xml.xsd +286 -0
  194. data/resources/kernel-4.5/metadata.xsd +711 -0
  195. data/resources/kernel-4.6/include/datacite-contributorType-v4.xsd +37 -0
  196. data/resources/kernel-4.6/include/datacite-dateType-v4.xsd +27 -0
  197. data/resources/kernel-4.6/include/datacite-descriptionType-v4.xsd +19 -0
  198. data/resources/kernel-4.6/include/datacite-funderIdentifierType-v4.xsd +16 -0
  199. data/resources/kernel-4.6/include/datacite-nameType-v4.xsd +10 -0
  200. data/resources/kernel-4.6/include/datacite-numberType-v4.xsd +12 -0
  201. data/resources/kernel-4.6/include/datacite-relatedIdentifierType-v4.xsd +37 -0
  202. data/resources/kernel-4.6/include/datacite-relationType-v4.xsd +57 -0
  203. data/resources/kernel-4.6/include/datacite-resourceType-v4.xsd +49 -0
  204. data/resources/kernel-4.6/include/datacite-titleType-v4.xsd +14 -0
  205. data/resources/kernel-4.6/include/xml.xsd +286 -0
  206. data/resources/kernel-4.6/metadata.xsd +712 -0
  207. data/resources/kernel-4.7/include/datacite-contributorType-v4.xsd +37 -0
  208. data/resources/kernel-4.7/include/datacite-dateType-v4.xsd +27 -0
  209. data/resources/kernel-4.7/include/datacite-descriptionType-v4.xsd +19 -0
  210. data/resources/kernel-4.7/include/datacite-funderIdentifierType-v4.xsd +16 -0
  211. data/resources/kernel-4.7/include/datacite-nameType-v4.xsd +10 -0
  212. data/resources/kernel-4.7/include/datacite-numberType-v4.xsd +12 -0
  213. data/resources/kernel-4.7/include/datacite-relatedIdentifierType-v4.xsd +39 -0
  214. data/resources/kernel-4.7/include/datacite-relationType-v4.xsd +59 -0
  215. data/resources/kernel-4.7/include/datacite-resourceType-v4.xsd +52 -0
  216. data/resources/kernel-4.7/include/datacite-titleType-v4.xsd +14 -0
  217. data/resources/kernel-4.7/include/xml.xsd +286 -0
  218. data/resources/kernel-4.7/metadata.xsd +715 -0
  219. data/resources/oecd/dfg-mappings.json +1866 -0
  220. data/resources/oecd/for-mappings.json +1101 -0
  221. data/resources/oecd/fos-mappings.json +198 -0
  222. data/resources/schema_org/jsonldcontext.json +7477 -0
  223. data/resources/spdx/licenses.json +5297 -0
  224. data/resources/xml.xsd +286 -0
  225. metadata +466 -179
  226. data/.travis.yml +0 -23
  227. data/lib/bolognese/crossref.rb +0 -233
  228. data/lib/bolognese/datacite.rb +0 -176
  229. data/lib/bolognese/date_utils.rb +0 -48
  230. data/lib/bolognese/github.rb +0 -106
  231. data/lib/bolognese/orcid.rb +0 -24
  232. data/lib/bolognese/schema_org.rb +0 -170
  233. data/spec/cli_spec.rb +0 -56
  234. data/spec/crossref_spec.rb +0 -190
  235. data/spec/datacite_spec.rb +0 -93
  236. data/spec/datacite_utils_spec.rb +0 -159
  237. data/spec/doi_utils_spec.rb +0 -89
  238. data/spec/fixtures/crossref.xml +0 -742
  239. data/spec/fixtures/datacite.xml +0 -40
  240. data/spec/fixtures/vcr_cassettes/Bolognese_CLI/read/crossref/as_crossref.yml +0 -760
  241. data/spec/fixtures/vcr_cassettes/Bolognese_CLI/read/crossref/as_datacite.yml +0 -1476
  242. data/spec/fixtures/vcr_cassettes/Bolognese_CLI/read/crossref/as_schema_org.yml +0 -1476
  243. data/spec/fixtures/vcr_cassettes/Bolognese_CLI/read/datacite/as_datacite.yml +0 -214
  244. data/spec/fixtures/vcr_cassettes/Bolognese_CLI/read/datacite/as_schema_org.yml +0 -384
  245. data/spec/fixtures/vcr_cassettes/Bolognese_CLI/read/schema_org/as_datacite.yml +0 -653
  246. data/spec/fixtures/vcr_cassettes/Bolognese_CLI/read/schema_org/as_schema_org.yml +0 -653
  247. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/doi_registration_agency/crossref.yml +0 -971
  248. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/doi_registration_agency/datacite.yml +0 -971
  249. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/doi_registration_agency/medra.yml +0 -971
  250. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/doi_registration_agency/not_found.yml +0 -971
  251. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/get_metadata/DOI_with_ORCID_ID.yml +0 -506
  252. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/get_metadata/DOI_with_SICI_DOI.yml +0 -214
  253. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/get_metadata/DOI_with_data_citation.yml +0 -901
  254. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/get_metadata/date_in_future.yml +0 -305
  255. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/get_metadata/journal_article.yml +0 -1080
  256. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/get_metadata/not_found_error.yml +0 -183
  257. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/get_metadata/posted_content.yml +0 -389
  258. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/get_metadata_as_datacite_xml/DOI_with_ORCID_ID.yml +0 -506
  259. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/get_metadata_as_datacite_xml/DOI_with_data_citation.yml +0 -901
  260. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/get_metadata_as_datacite_xml/with_ORCID_ID.yml +0 -366
  261. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/get_metadata_as_datacite_xml/with_data_citation.yml +0 -719
  262. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/get_metadata_as_datacite_xml/with_editor.yml +0 -930
  263. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/get_metadata_as_string/DOI_with_data_citation.yml +0 -719
  264. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/normalize_doi/SICI_doi.yml +0 -930
  265. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/normalize_doi/doi.yml +0 -930
  266. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/normalize_doi/doi_from_url_without_doi_proxy.yml +0 -930
  267. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/normalize_doi/doi_prefix_too_long.yml +0 -930
  268. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/normalize_doi/doi_prefix_with_string.yml +0 -930
  269. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/normalize_doi/doi_with_protocol.yml +0 -930
  270. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/normalize_doi/dx_doi_org_url.yml +0 -930
  271. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/normalize_doi/https_url.yml +0 -930
  272. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/normalize_doi/not_valid_doi_prefix.yml +0 -930
  273. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/normalize_ids/doi.yml +0 -930
  274. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/normalize_ids/url.yml +0 -930
  275. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/normalize_url/doi.yml +0 -930
  276. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/normalize_url/url.yml +0 -930
  277. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/parse_attribute/array.yml +0 -930
  278. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/parse_attribute/hash.yml +0 -930
  279. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/parse_attribute/nil.yml +0 -930
  280. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/parse_attribute/string.yml +0 -930
  281. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/parse_attributes/array.yml +0 -930
  282. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/parse_attributes/hash.yml +0 -930
  283. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/parse_attributes/nil.yml +0 -930
  284. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/parse_attributes/string.yml +0 -930
  285. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/validate_url/DOI.yml +0 -930
  286. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/validate_url/URL.yml +0 -930
  287. data/spec/fixtures/vcr_cassettes/Bolognese_Crossref/validate_url/string.yml +0 -930
  288. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/get_metadata/BlogPosting.yml +0 -477
  289. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/get_metadata/Dataset.yml +0 -1925
  290. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/get_metadata/Date.yml +0 -458
  291. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/get_metadata_as_string/Dataset.yml +0 -173
  292. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_alternate_identifiers/insert.yml +0 -173
  293. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_contributors/insert.yml +0 -173
  294. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_contributors/none.yml +0 -173
  295. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_creators/insert.yml +0 -173
  296. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_dates/insert.yml +0 -173
  297. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_descriptions/insert.yml +0 -155
  298. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_identifier/doi.yml +0 -173
  299. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_person/creator.yml +0 -173
  300. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_person/creator_given_and_family_name.yml +0 -173
  301. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_person/creator_only_name.yml +0 -173
  302. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_publication_year/insert.yml +0 -173
  303. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_publisher/insert.yml +0 -173
  304. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_related_identifiers/get_related_identifier_type.yml +0 -173
  305. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_related_identifiers/get_related_identifier_type_DOI.yml +0 -173
  306. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_related_identifiers/get_related_identifier_type_URL.yml +0 -173
  307. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_related_identifiers/insert.yml +0 -173
  308. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_related_identifiers/rel_identifiers.yml +0 -173
  309. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_resource_type/insert.yml +0 -173
  310. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_rights_list/insert.yml +0 -173
  311. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_subjects/insert.yml +0 -173
  312. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_titles/doi.yml +0 -173
  313. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_titles/insert.yml +0 -173
  314. data/spec/fixtures/vcr_cassettes/Bolognese_Datacite/insert_version/insert.yml +0 -173
  315. data/spec/fixtures/vcr_cassettes/Bolognese_Metadata/find_PID_provider/crossref.yml +0 -44
  316. data/spec/fixtures/vcr_cassettes/Bolognese_Metadata/find_PID_provider/crossref_doi_not_url.yml +0 -44
  317. data/spec/fixtures/vcr_cassettes/Bolognese_Metadata/find_PID_provider/datacite.yml +0 -44
  318. data/spec/fixtures/vcr_cassettes/Bolognese_Metadata/find_PID_provider/datacite_doi_http.yml +0 -44
  319. data/spec/fixtures/vcr_cassettes/Bolognese_Metadata/find_PID_provider/orcid.yml +0 -44
  320. data/spec/fixtures/vcr_cassettes/Bolognese_SchemaOrg/get_metadata/BlogPosting.yml +0 -632
  321. data/spec/fixtures/vcr_cassettes/Bolognese_SchemaOrg/get_metadata/not_found_error.yml +0 -93
  322. data/spec/metadata_spec.rb +0 -41
  323. data/spec/orcid_spec.rb +0 -23
  324. data/spec/schema_org_spec.rb +0 -33
  325. data/spec/spec_helper.rb +0 -88
  326. data/spec/utils_spec.rb +0 -107
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env rake
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler'
4
5
  require 'rake'
data/bin/bolognese CHANGED
@@ -2,4 +2,8 @@
2
2
 
3
3
  require File.expand_path("../../lib/bolognese", __FILE__)
4
4
 
5
- Bolognese::CLI.start
5
+ if (ARGV & %w(--version -v help --help)).empty?
6
+ Bolognese::CLI.start(ARGV.dup.unshift("convert"))
7
+ else
8
+ Bolognese::CLI.start
9
+ end
data/bolognese.gemspec CHANGED
@@ -8,33 +8,45 @@ Gem::Specification.new do |s|
8
8
  s.homepage = "https://github.com/datacite/bolognese"
9
9
  s.summary = "Ruby client library for conversion of DOI Metadata"
10
10
  s.date = Date.today
11
- s.description = "Convert DOI metadata to and from Crossref and DataCite XML, as well as schema.org/JSON-LD"
11
+ s.description = "Ruby gem and command-line utility for conversion of DOI metadata from and to different metadata formats, including schema.org."
12
12
  s.require_paths = ["lib"]
13
13
  s.version = Bolognese::VERSION
14
14
  s.extra_rdoc_files = ["README.md"]
15
15
  s.license = 'MIT'
16
+ s.required_ruby_version = ['>= 3.2', '< 4.1']
16
17
 
17
- # Declary dependencies here, rather than in the Gemfile
18
- s.add_dependency 'maremma', '~> 3.5'
19
- s.add_dependency 'nokogiri', '~> 1.6', '>= 1.6.8'
20
- s.add_dependency 'builder', '~> 3.2', '>= 3.2.2'
21
- s.add_dependency 'activesupport', '~> 4.2', '>= 4.2.5'
22
- s.add_dependency 'dotenv', '~> 2.1', '>= 2.1.1'
23
- s.add_dependency 'thor', '~> 0.19'
24
- s.add_dependency 'namae', '~> 0.10.2'
25
- s.add_dependency 'postrank-uri', '~> 1.0', '>= 1.0.18'
26
- s.add_development_dependency 'bundler', '~> 1.0'
27
- s.add_development_dependency 'rspec', '~> 3.4'
28
- s.add_development_dependency 'rspec-xsd', '~> 0.1.0'
29
- s.add_development_dependency 'rake', '~> 12.0'
30
- s.add_development_dependency 'rack-test', '~> 0'
31
- s.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.3'
32
- s.add_development_dependency 'webmock', '~> 1.22', '>= 1.22.3'
33
- s.add_development_dependency 'codeclimate-test-reporter', '~> 1.0', '>= 1.0.0'
34
- s.add_development_dependency 'simplecov', '~> 0.12.0'
18
+ # Declare dependencies here, rather than in the Gemfile
19
+ s.add_dependency 'maremma', '~> 6.0'
20
+ s.add_dependency 'nokogiri', '~> 1.19', '>= 1.19.1'
21
+ s.add_dependency 'loofah', '~> 2.25'
22
+ s.add_dependency 'builder', '~> 3.3'
23
+ s.add_dependency 'activesupport', "~> 8.1", ">= 8.1.2"
24
+ s.add_dependency 'bibtex-ruby', '~> 6.2'
25
+ s.add_dependency 'thor', '~> 1.5'
26
+ s.add_dependency 'namae', '~> 1.2'
27
+ s.add_dependency 'edtf', '~> 3.2'
28
+ s.add_dependency 'citeproc-ruby', '~> 2.1', '>= 2.1.8'
29
+ s.add_dependency 'csl-styles', '~> 2.0', '>= 2.0.2'
30
+ s.add_dependency 'iso8601', '~> 0.13.0'
31
+ s.add_dependency 'json-ld-preloaded', '~> 3.3', '>= 3.3.2'
32
+ s.add_dependency 'jsonlint', '~> 0.4.0'
33
+ s.add_dependency 'oj', '~> 3.16', '>= 3.16.15'
34
+ s.add_dependency 'rdf-turtle', '~> 3.3', '>= 3.3.1'
35
+ s.add_dependency 'rdf-rdfxml', '~> 3.3'
36
+ s.add_dependency 'gender_detector', '~> 2.1'
37
+ s.add_dependency 'concurrent-ruby', '~> 1.3', '>= 1.3.6'
38
+ s.add_dependency 'csv', '~> 3.3', '>= 3.3.5'
39
+ s.add_development_dependency 'bundler', '>= 2.0'
40
+ s.add_development_dependency 'irb'
41
+ s.add_development_dependency 'rspec', '~> 3.13', '>= 3.13.2'
42
+ s.add_development_dependency 'rake', '~> 13.3', '>= 13.3.1'
43
+ s.add_development_dependency 'rack-test', '~> 2.2'
44
+ s.add_development_dependency 'vcr', '~> 6.4'
45
+ s.add_development_dependency 'webmock', '~> 3.26', '>= 3.26.1'
46
+ s.add_development_dependency 'simplecov', '0.22.0'
47
+ s.add_development_dependency 'byebug'
35
48
 
36
49
  s.require_paths = ["lib"]
37
- s.files = `git ls-files`.split($/)
38
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
50
+ s.files = `git ls-files`.split($/).reject { |f| f.match(%r{^(test|spec|features)/}) }
39
51
  s.executables = ["bolognese"]
40
52
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ # turn array into hash or nil, depending on array size.
4
+ # Reverses Array.wrap, but uses self to allow chaining with Array.wrap
5
+ class Array
6
+ def unwrap
7
+ case self.length
8
+ when 0 then nil
9
+ when 1 then self.first
10
+ else self
11
+ end
12
+ end
13
+ end
@@ -1,62 +1,176 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'namae'
2
4
 
3
5
  module Bolognese
4
6
  module AuthorUtils
5
- # only assume personal name when using sort-order: "Turing, Alan"
6
- def get_one_author(author, options = {})
7
- orcid = get_name_identifier(author)
8
- author = author.fetch("creatorName", nil)
9
7
 
10
- return { "Name" => "" } if author.strip.blank?
8
+ IDENTIFIER_SCHEME_URIS = {
9
+ "ORCID" => "https://orcid.org/"
10
+ }
11
11
 
12
- author = cleanup_author(author)
13
- names = Namae.parse(author)
12
+ def get_one_author(author)
13
+ # author is a string
14
+ author = { "creatorName" => author } if author.is_a?(String)
14
15
 
15
- if names.blank? || is_personal_name?(author).blank?
16
- { "@type" => "Agent",
17
- "@id" => orcid,
18
- "Name" => author }.compact
19
- else
20
- name = names.first
16
+ # malformed XML
17
+ return nil if author.fetch("creatorName", nil).is_a?(Array)
18
+
19
+ name = parse_attributes(author.fetch("creatorName", nil)) ||
20
+ parse_attributes(author.fetch("contributorName", nil))
21
+ given_name = parse_attributes(author.fetch("givenName", nil))
22
+ family_name = parse_attributes(author.fetch("familyName", nil))
23
+ name = cleanup_author(name)
24
+ name = [family_name, given_name].join(", ") if family_name.present? && given_name.present?
25
+ contributor_type = parse_attributes(author.fetch("contributorType", nil))
26
+
27
+ name_type = parse_attributes(author.fetch("creatorName", nil), content: "nameType", first: true) || parse_attributes(author.fetch("contributorName", nil), content: "nameType", first: true)
28
+
29
+ name_identifiers = Array.wrap(author.fetch("nameIdentifier", nil)).map do |ni|
30
+ name_identifier = ni["__content__"].strip if ni["__content__"].present?
31
+ if ni["nameIdentifierScheme"] == "ORCID"
32
+ {
33
+ "nameIdentifier" => normalize_orcid(name_identifier),
34
+ "schemeUri" => "https://orcid.org",
35
+ "nameIdentifierScheme" => "ORCID" }.compact
36
+ elsif ni["nameIdentifierScheme"] == "ROR"
37
+ {
38
+ "nameIdentifier" => normalize_ror(name_identifier),
39
+ "schemeUri" => "https://ror.org",
40
+ "nameIdentifierScheme" => "ROR" }.compact
41
+ else
42
+ {
43
+ "nameIdentifier" => name_identifier,
44
+ "schemeUri" => ni.fetch("schemeURI", nil),
45
+ "nameIdentifierScheme" => ni["nameIdentifierScheme"] }.compact
46
+ end
47
+ end.presence
21
48
 
22
- { "@type" => "Person",
23
- "@id" => orcid,
24
- "givenName" => name.given,
25
- "familyName" => name.family }.compact
49
+ author = { "nameType" => name_type,
50
+ "name" => name,
51
+ "givenName" => given_name,
52
+ "familyName" => family_name,
53
+ "nameIdentifiers" => name_identifiers,
54
+ "affiliation" => get_affiliations(author.fetch("affiliation", nil)),
55
+ "contributorType" => contributor_type }.compact
56
+
57
+ return author if family_name.present?
58
+
59
+ if is_personal_name?(author)
60
+ Namae.options[:include_particle_in_family] = true
61
+ names = Namae.parse(name)
62
+ parsed_name = names.first
63
+
64
+ if parsed_name.present?
65
+ given_name = parsed_name.given
66
+ family_name = parsed_name.family
67
+ name = [family_name, given_name].join(", ")
68
+ else
69
+ given_name = nil
70
+ family_name = nil
71
+ end
72
+
73
+ { "nameType" => "Personal",
74
+ "name" => name,
75
+ "givenName" => given_name,
76
+ "familyName" => family_name,
77
+ "nameIdentifiers" => Array.wrap(name_identifiers),
78
+ "affiliation" => Array.wrap(author.fetch("affiliation", nil)),
79
+ "contributorType" => contributor_type }.compact
80
+ else
81
+ { "nameType" => name_type,
82
+ "name" => name,
83
+ "nameIdentifiers" => Array.wrap(name_identifiers),
84
+ "affiliation" => Array.wrap(author.fetch("affiliation", nil)),
85
+ "contributorType" => contributor_type }.compact
26
86
  end
27
87
  end
28
88
 
29
89
  def cleanup_author(author)
90
+ return nil unless author.present?
91
+
30
92
  # detect pattern "Smith J.", but not "Smith, John K."
31
93
  author = author.gsub(/[[:space:]]([A-Z]\.)?(-?[A-Z]\.)$/, ', \1\2') unless author.include?(",")
32
94
 
95
+ # remove spaces around hyphens
96
+ author = author.gsub(" - ", "-")
97
+
33
98
  # titleize strings
34
99
  # remove non-standard space characters
35
- author.my_titleize
36
- .gsub(/[[:space:]]/, ' ')
100
+ author.gsub(/[[:space:]]/, ' ')
37
101
  end
38
102
 
39
103
  def is_personal_name?(author)
40
- return true if author.include?(",")
104
+ return false if author.fetch("nameType", nil) == "Organizational"
105
+ return true if Array.wrap(author.fetch("nameIdentifiers", nil)).find { |a| a["nameIdentifierScheme"] == "ORCID" }.present? ||
106
+ author.fetch("familyName", "").present? ||
107
+ (author.fetch("name", "").include?(",") &&
108
+ author.fetch("name", "").exclude?(";")) ||
109
+ name_exists?(author.fetch("name", "").split(" ").first)
110
+ false
111
+ end
41
112
 
42
- # lookup given name
43
- #::NameDetector.name_exists?(author.split.first)
113
+ # recognize given name if we have loaded ::NameDetector data, e.g. in a Rails initializer
114
+ def name_exists?(name)
115
+ return false unless name_detector.present?
116
+
117
+ name_detector.name_exists?(name)
44
118
  end
45
119
 
46
120
  # parse array of author strings into CSL format
47
- def get_authors(authors, options={})
48
- Array(authors).map { |author| get_one_author(author, options) }
121
+ def get_authors(authors)
122
+ Array.wrap(authors).map { |author| get_one_author(author) }.compact
49
123
  end
50
124
 
51
- # pase nameIdentifier from DataCite
52
- def get_name_identifier(author)
53
- name_identifier = author.dig("nameIdentifier", "text")
54
- name_identifier_scheme = author.dig("nameIdentifier", "nameIdentifierScheme") || "ORCID"
55
- if name_identifier_scheme.downcase == "orcid" && name_identifier = validate_orcid(name_identifier)
56
- "http://orcid.org/#{name_identifier}"
57
- else
58
- nil
59
- end
125
+ def authors_as_string(authors)
126
+ Array.wrap(authors).map do |a|
127
+ if a["familyName"].present?
128
+ [a["familyName"], a["givenName"]].join(", ")
129
+ elsif a["type"] == "Person"
130
+ a["name"]
131
+ elsif a["name"].present?
132
+ "{" + a["name"] + "}"
133
+ end
134
+ end.join(" and ").presence
135
+ end
136
+
137
+ def get_affiliations(affiliations)
138
+ Array.wrap(affiliations).map do |a|
139
+ affiliation_identifier = nil
140
+ if a.is_a?(String)
141
+ name = a.squish
142
+ affiliation_identifier_scheme = nil
143
+ scheme_uri = nil
144
+ else
145
+ scheme_uri = a["schemeURI"]
146
+ if a["affiliationIdentifier"].present?
147
+ affiliation_identifier = a["affiliationIdentifier"]
148
+ if a["schemeURI"].present?
149
+ schemeURI = a["schemeURI"].end_with?("/") ? a["schemeURI"] : a["schemeURI"] + "/"
150
+ end
151
+ affiliation_identifier = !affiliation_identifier.to_s.start_with?("https://") && schemeURI.present? ? normalize_id(schemeURI + affiliation_identifier) : normalize_id(affiliation_identifier)
152
+ # The normalize_id(affiliation_identifier) method currently discards affiliation identifiers that don't start with a URL,
153
+ # for example: affiliation_identifier = "05bp8ka05".
154
+ # To address this issue, we are introducing the following change to handle such affiliation identifiers.
155
+ # when `normalize_id` method could not normalize, it returns nil, hence we have following condition
156
+ if affiliation_identifier.nil?
157
+ if a["affiliationIdentifierScheme"] == "ROR"
158
+ scheme_uri = "https://ror.org"
159
+ affiliation_identifier = normalize_ror(a["affiliationIdentifier"])
160
+ else
161
+ affiliation_identifier = a["affiliationIdentifier"]
162
+ end
163
+ end
164
+ end
165
+ name = a["__content__"].to_s.squish.presence
166
+ affiliation_identifier_scheme = a["affiliationIdentifierScheme"]
167
+ end
168
+
169
+ { "name" => name,
170
+ "affiliationIdentifier" => affiliation_identifier,
171
+ "affiliationIdentifierScheme" => affiliation_identifier_scheme,
172
+ "schemeUri" => scheme_uri }.compact
173
+ end.presence
60
174
  end
61
175
  end
62
176
  end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Minimal patch for csl-ruby and citeproc-ruby compatibility
4
+ # Root cause: 'contributor' is not recognized as a names variable in citeproc gem
5
+ # https://github.com/inukshuk/citeproc/blob/121fa4a950b9bd71960e42d20db96bcea1165201/lib/citeproc/variable.rb#L20-L24
6
+
7
+ module CiteProc
8
+ class Variable
9
+ # Unfreeze, modify, and refreeze the fields to add 'contributor' and 'accepted-date'
10
+ if @fields
11
+ # Unfreeze the fields hash temporarily
12
+ fields_dup = @fields.dup
13
+
14
+ # Add contributor to names (make a new unfrozen array)
15
+ fields_dup[:names] = (@fields[:names] + [:contributor]).uniq
16
+
17
+ # Add accepted-date to dates (make a new unfrozen array)
18
+ fields_dup[:date] = (@fields[:date] + [:'accepted-date']).uniq
19
+
20
+ # Rebuild the types mapping - only use actual type keys, not aliases like :all, :any, etc.
21
+ types_hash = Hash[*[:date, :names, :number, :text].map { |k| fields_dup[k].map { |n| [n, k] } }.flatten]
22
+
23
+ # Update the class instance variables
24
+ @fields = fields_dup
25
+ @types = Hash.new { |h,k| h.fetch(k.to_sym, nil) }.merge(types_hash).freeze
26
+
27
+ # Rebuild @factories from the new @types
28
+ # This maps each field name to its Variable subclass (Names, Date, Text, Number)
29
+ @factories = Hash.new { |h,k| h.fetch(k.to_s.intern, CiteProc::Variable) }.merge(
30
+ Hash[*@types.map { |field_name, type|
31
+ [field_name, CiteProc.const_get(type.to_s.capitalize)]
32
+ }.flatten]
33
+ ).freeze
34
+
35
+ # Recreate the aliases
36
+ @fields[:name] = @fields[:names]
37
+ @fields[:dates] = @fields[:date]
38
+ @fields[:numbers] = @fields[:number]
39
+
40
+ # Recreate :all and :any
41
+ @fields[:all] = @fields[:any] =
42
+ [:date, :names, :text, :number].reduce([]) { |s,a| s.concat(@fields[a]) }.sort
43
+
44
+ # Refreeze fields
45
+ @fields.freeze
46
+ end
47
+ end
48
+ end
data/lib/bolognese/cli.rb CHANGED
@@ -1,9 +1,16 @@
1
1
  # encoding: UTF-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "thor"
4
5
 
6
+ require_relative 'doi_utils'
7
+ require_relative 'utils'
8
+
5
9
  module Bolognese
6
10
  class CLI < Thor
11
+ include Bolognese::DoiUtils
12
+ include Bolognese::Utils
13
+
7
14
  def self.exit_on_failure?
8
15
  true
9
16
  end
@@ -16,29 +23,29 @@ module Bolognese
16
23
  puts Bolognese::VERSION
17
24
  end
18
25
 
19
- desc "read pid", "read metadata for PID"
20
- method_option :as, default: "schema_org"
21
- def read(pid)
22
- provider = Metadata.new(id: pid).provider
23
-
24
- case
25
- when provider == "crossref" && options[:as] == "crossref"
26
- puts Crossref.new(id: pid).raw
27
- when provider == "crossref" && options[:as] == "datacite"
28
- puts Crossref.new(id: pid).as_datacite
29
- when provider == "crossref"
30
- puts Crossref.new(id: pid).as_schema_org
31
- when provider == "datacite" && options[:as] == "datacite"
32
- puts Datacite.new(id: pid).raw
33
- when provider == "datacite"
34
- puts Datacite.new(id: pid).as_schema_org
35
- when provider == "schema_org" && options[:as] == "datacite"
36
- puts SchemaOrg.new(id: pid).as_datacite
37
- when provider == "schema_org"
38
- puts SchemaOrg.new(id: pid).as_schema_org
26
+ desc "", "convert metadata"
27
+ method_option :from, aliases: "-f"
28
+ method_option :to, aliases: "-t", default: "schema_org"
29
+ method_option :regenerate, :type => :boolean, :force => false
30
+ method_option :style, aliases: "-s", default: "apa"
31
+ method_option :locale, aliases: "-l", default: "en-US"
32
+ method_option :show_errors, :type => :boolean, :force => false
33
+ def convert(input)
34
+ metadata = Metadata.new(input: input,
35
+ from: options[:from],
36
+ regenerate: options[:regenerate],
37
+ style: options[:style],
38
+ locale: options[:locale],
39
+ show_errors: options[:show_errors])
40
+ to = options[:to] || "schema_org"
41
+
42
+ if options[:show_errors] && !metadata.valid?
43
+ $stderr.puts metadata.errors
39
44
  else
40
- puts "not implemented"
45
+ puts metadata.send(to)
41
46
  end
42
47
  end
48
+
49
+ default_task :convert
43
50
  end
44
51
  end