relaton 3.1.3 → 3.1.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf214dd5828ef52d54652cd3c01d5406527e7dd0f6be2c52447a72889e7ed3c8
4
- data.tar.gz: 48c41d919e828654ae0ddfd8fc0c6dcf2dafc912b65b58b493964145eb936ca6
3
+ metadata.gz: 1ea5d8ada503e918f9bca0be141bc0ae76b7bdf89c634c2588b6609eb06251bf
4
+ data.tar.gz: 2b5578cd9fbb7907b1c9c4be0b3e066fbac0fa8884e59264a365cc55e5737f40
5
5
  SHA512:
6
- metadata.gz: 612e007cdc0a28b1eb0ac6ef9e0e563f067daa8532a25002d76835233e43b5e5051e2af133ad078a96be66d73c56c4ca58f5e3c675e51b8331cb58e3d842060c
7
- data.tar.gz: 55ba69a723f91403724139457801a0fa92842208d5cc06be86fd7260a8507e85ccccbe3eb454f82553247130e1e072b1def59eee9a6c54c9b2086b8c6a29bd8d
6
+ metadata.gz: a64557918b5ae5ab276bc3849f4c73bb20e31a3ddc618a7db33cce060c40a2f8780303181f2c6dfa94d0309d0e75146337690be7eb296ce469b298ecf6cd0641
7
+ data.tar.gz: 44d22a95a792c4396b37c223ad44077bd87562a4c8e5f26889504e86078a229357baacbe1bbc4217dbe4bfed55614dca7e64aaeee96c7c8804336cd517a06956
data/README.adoc CHANGED
@@ -66,15 +66,25 @@ e.g. `get("ISO 19115-1", "2014", all_parts: true)` is transformed into a referen
66
66
 
67
67
  === Configuration
68
68
 
69
- * `use_api` - `true` if it needs to use an online cache, `false` if not. The default value is `true`.
70
- * `api_host` - URL of an online cache. The default value is https://api.relaton.org.
69
+ * `use_api` - `true` to ask api.relaton.org before the flavor's own fetch on a cache miss; the flavor still answers whatever the API does not. The default value is the `RELATON_USE_API` environment variable (`1`, `true`, `yes` or `on` turn it on), else `false`.
70
+ * `api_host` - URL of the API. The default value is the `RELATON_API_HOST` environment variable, else https://api.relaton.org.
71
+ * `api_timeout` - open and read timeout of an API request, in seconds. The default value is `10`.
72
+ * `offline` - `true` to answer every fetch from the local cache only, with no network request. The default value is the `RELATON_OFFLINE` environment variable, else `false`.
73
+
74
+ The `relaton` command line turns the API on for one run with `--api` and off with `--no-api` (on `relaton fetch` and `relaton collection fetch`); with neither flag it follows `RELATON_USE_API`:
75
+
76
+ [source,sh]
77
+ ----
78
+ relaton fetch "IETF RFC 8341" --api
79
+ RELATON_USE_API=1 relaton fetch "IETF RFC 8341"
80
+ ----
71
81
 
72
82
  [source,ruby]
73
83
  ----
74
84
  require "relaton"
75
85
  => true
76
86
 
77
- Relaton.configure do |conf|
87
+ Relaton::Db.configure do |conf|
78
88
  conf.use_api = true
79
89
  conf.api_host = "https://api.relaton.org"
80
90
  end
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Relaton
4
+ module Bib
5
+ module Converter
6
+ module Endnote
7
+ class FromEndnote
8
+ TAG_LINE = /\A%([A-Z@]) (.*)\z/
9
+
10
+ # @param refer_str [String]
11
+ # @return [Hash{String=>Relaton::Bib::ItemData}] keyed by the
12
+ # first title (Refer has no identifier tag), falling back to
13
+ # the record position
14
+ def self.parse(refer_str)
15
+ refer_str.split(/\n\s*\n/).map(&:lines).reject(&:empty?)
16
+ .each_with_object({}).with_index do |(record_lines, hash), i|
17
+ item = new(record_lines).item
18
+ title = Array(item.title).first&.content.to_s
19
+ hash[title.empty? ? "record-#{i + 1}" : title] = item
20
+ end
21
+ end
22
+
23
+ # @param record_lines [Array<String>]
24
+ def initialize(record_lines)
25
+ @tags = Hash.new { |h, k| h[k] = [] }
26
+ record_lines.each do |line|
27
+ next unless (m = line.chomp.match(TAG_LINE))
28
+
29
+ @tags[m[1]] << m[2]
30
+ end
31
+ end
32
+
33
+ # @return [Relaton::Bib::ItemData]
34
+ def item
35
+ ItemData.new(
36
+ docidentifier: fetch_docid,
37
+ title: fetch_title,
38
+ date: fetch_date,
39
+ contributor: fetch_contributor,
40
+ edition: fetch_edition,
41
+ series: fetch_series,
42
+ keyword: fetch_keyword,
43
+ source: fetch_source,
44
+ )
45
+ end
46
+
47
+ private
48
+
49
+ # Refer has no identifier tag; a %R is some dialects' report
50
+ # number, not a docidentifier — none is invented here.
51
+ def fetch_docid
52
+ []
53
+ end
54
+
55
+ def fetch_title
56
+ @tags["T"].map { |v| Title.new(type: "title-main", content: v) }
57
+ end
58
+
59
+ # Refer dates are "YYYY" or a free-form date string.
60
+ def fetch_date
61
+ @tags["D"].map do |v|
62
+ on = v.match?(/\A\d{4}\z/) ? v : (::Date.parse(v).to_s rescue v)
63
+ Bib::Date.new(type: "published", at: on)
64
+ end
65
+ end
66
+
67
+ # "Surname, Forename" names a person; a bare token is an
68
+ # organization (the same convention the RIS importer applies to
69
+ # this converter's own output).
70
+ def fetch_contributor
71
+ contribs = []
72
+ @tags["A"].each do |name|
73
+ contribs << if name.include?(",")
74
+ person_contributor(name)
75
+ else
76
+ org_contributor(name, "author")
77
+ end
78
+ end
79
+ @tags["I"].each { |name| contribs << org_contributor(name, "publisher") }
80
+ contribs
81
+ end
82
+
83
+ def person_contributor(name)
84
+ parts = name.split(", ")
85
+ surname = LocalizedString.new(content: parts.first)
86
+ forename = (parts[1] || "").split.map { |fn| FullNameType::Forename.new(content: fn) }
87
+ person = Person.new(name: FullName.new(surname: surname, forename: forename))
88
+ Contributor.new(person: person, role: [Contributor::Role.new(type: "author")])
89
+ end
90
+
91
+ def org_contributor(name, role)
92
+ org = Organization.new(name: [TypedLocalizedString.new(content: name)])
93
+ Contributor.new(organization: org, role: [Contributor::Role.new(type: role)])
94
+ end
95
+
96
+ def fetch_edition
97
+ Edition.new(content: @tags["@"].first.to_s) if @tags["@"].any?
98
+ end
99
+
100
+ def fetch_series
101
+ series = []
102
+ @tags["J"].each { |v| series << Series.new(type: "journal", title: Title.new(content: v)) }
103
+ @tags["S"].each { |v| series << Series.new(title: Title.new(content: v)) }
104
+ series
105
+ end
106
+
107
+ def fetch_keyword
108
+ @tags["K"].map { |v| Keyword.new(vocab: LocalizedString.new(content: v)) }
109
+ end
110
+
111
+ def fetch_source
112
+ @tags["U"].map { |v| Uri.new(type: "src", content: v) }
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Relaton
4
+ module Bib
5
+ module Converter
6
+ module Endnote
7
+ class ToEndnote
8
+ # @param item [Relaton::Bib::ItemData]
9
+ def initialize(item)
10
+ @item = item
11
+ end
12
+
13
+ # @return [String] one Refer record (no trailing blank line)
14
+ def to_s
15
+ lines = []
16
+ add_authors(lines)
17
+ add_field(lines, "%T", primary_title)
18
+ add_field(lines, "%D", published_year)
19
+ add_field(lines, "%@", @item.edition&.to_s)
20
+ add_field(lines, "%I", publisher_name)
21
+ add_journal(lines)
22
+ add_series(lines)
23
+ Array(@item.keyword).each { |k| add_field(lines, "%K", k.vocab.content.to_s) }
24
+ add_field(lines, "%U", source_uri)
25
+ lines.join("\n") + "\n"
26
+ end
27
+
28
+ private
29
+
30
+ def add_field(lines, tag, value)
31
+ lines << "#{tag} #{value}" if value && !value.empty?
32
+ end
33
+
34
+ # The same authorish/publisher split the RIS renderer makes.
35
+ def add_authors(lines)
36
+ Array(@item.contributor).each do |c|
37
+ roles = Array(c.role).map(&:type).compact
38
+ authorish = (roles & %w[author performer editor]).any?
39
+ if authorish && c.person
40
+ out = person_display_name(c.person.name)
41
+ add_field(lines, "%A", out) unless out.empty?
42
+ elsif authorish && c.organization
43
+ out = org_name(c.organization)
44
+ add_field(lines, "%A", out) unless out.empty?
45
+ end
46
+ end
47
+ end
48
+
49
+ def person_display_name(name)
50
+ return "" unless name
51
+
52
+ fore = Array(name.forename).map { |f| f.respond_to?(:content) ? f.content.to_s : f.to_s }.join(" ")
53
+ sur = name.surname.respond_to?(:content) ? name.surname.content.to_s : name.surname.to_s
54
+ complete = name.completename.respond_to?(:content) ? name.completename.content.to_s : name.completename.to_s
55
+ return "#{sur}, #{fore}" unless fore.empty? || sur.empty?
56
+ return sur unless sur.empty?
57
+
58
+ complete
59
+ end
60
+
61
+ def org_name(org)
62
+ name = Array(org.name).map { |n| n.respond_to?(:content) ? n.content.to_s : n.to_s }.find(&:itself)
63
+ name || org.abbreviation.to_s
64
+ end
65
+
66
+ def publisher_name
67
+ pub = Array(@item.contributor).find do |c|
68
+ Array(c.role).map(&:type).include?("publisher") && c.organization
69
+ end
70
+ pub && org_name(pub.organization)
71
+ end
72
+
73
+ # %J is the journal series; %S a plain series. An item carries at
74
+ # most one of each in this mapping.
75
+ def add_journal(lines)
76
+ journal = Array(@item.series).find { |s| s.type == "journal" }
77
+ add_field(lines, "%J", series_title(journal)) if journal
78
+ end
79
+
80
+ def add_series(lines)
81
+ series = Array(@item.series).reject { |s| s.type == "journal" }.first
82
+ add_field(lines, "%S", series_title(series)) if series
83
+ end
84
+
85
+ def series_title(series)
86
+ Array(series.title).map { |t| t.respond_to?(:content) ? t.content.to_s : t.to_s }.find(&:itself)
87
+ end
88
+
89
+ def primary_title
90
+ Titles.of(@item)
91
+ end
92
+
93
+ def published_year
94
+ date = Array(@item.date).find { |d| %w[published issued].include?(d.type.to_s) } || @item.date.first
95
+ value = date && (date.at || date.from || date.to)
96
+ value.to_s[/\d{4}/]
97
+ end
98
+
99
+ def source_uri
100
+ Array(@item.source).map { |s| s.respond_to?(:content) ? s.content.to_s : s.to_s }
101
+ .find { |u| u.start_with?("http") }
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "endnote/from_endnote"
4
+ require_relative "endnote/to_endnote"
5
+
6
+ module Relaton
7
+ module Bib
8
+ module Converter
9
+ module Endnote
10
+ # Refer-format field tags (the EndNote "tagged format"): one
11
+ # `%X value` line per field, records separated by a blank line.
12
+ TAGS = {
13
+ author: "%A", title: "%T", date: "%D", publisher: "%I",
14
+ edition: "%@", keyword: "%K", url: "%U", journal: "%J",
15
+ series: "%S",
16
+ }.freeze
17
+
18
+ # ItemData -> Refer string
19
+ def self.from_item(item)
20
+ ToEndnote.new(item).to_s
21
+ end
22
+
23
+ # Refer string -> Hash{String=>ItemData}
24
+ def self.to_item(refer_str)
25
+ FromEndnote.parse(refer_str)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,144 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Relaton
4
+ module Bib
5
+ module Converter
6
+ module Ris
7
+ # One TY..ER record per entry; tags are `XX - value` lines.
8
+ class FromRis
9
+ # ELEC backs two entry types; the reverse pairs it with the
10
+ # webresource face the renderer's default pairs with.
11
+ REVERSE_ENTRY_TYPES = {
12
+ "STD" => "standard", "BOOK" => "book", "JOUR" => "article",
13
+ "CHAP" => "inbook", "CONF" => "inproceedings", "RPRT" => "report",
14
+ "THES" => "thesis", "ELEC" => "webresource",
15
+ }.freeze
16
+
17
+ TAG_LINE = /\A([A-Z0-9]{2}) - ?(.*)\z/
18
+
19
+ # @param ris_str [String]
20
+ # @return [Hash{String=>Relaton::Bib::ItemData}] keyed by the ID
21
+ # tag (falling back to the docidentifier, then the record
22
+ # position)
23
+ def self.parse(ris_str)
24
+ records = []
25
+ current = nil
26
+ ris_str.each_line do |line|
27
+ line = line.chomp
28
+ if line.start_with?("TY - ")
29
+ current = [line]
30
+ elsif current
31
+ current << line
32
+ # The renderer writes "ER - " with a trailing space; real
33
+ # files commonly stop at the dash.
34
+ if line.start_with?("ER -")
35
+ records << current
36
+ current = nil
37
+ end
38
+ end
39
+ end
40
+ records.each_with_object({}).with_index do |(record, hash), i|
41
+ item = new(record).item
42
+ hash[record_key(item) || "record-#{i + 1}"] = item
43
+ end
44
+ end
45
+
46
+ # @param record_lines [Array<String>]
47
+ def initialize(record_lines)
48
+ @tags = Hash.new { |h, k| h[k] = [] }
49
+ record_lines.each do |line|
50
+ next unless (m = line.chomp.match(TAG_LINE))
51
+
52
+ @tags[m[1]] << m[2]
53
+ end
54
+ end
55
+
56
+ # @return [Relaton::Bib::ItemData]
57
+ def item
58
+ ItemData.new(
59
+ type: entry_type,
60
+ docidentifier: fetch_docid,
61
+ title: fetch_title,
62
+ date: fetch_date,
63
+ contributor: fetch_contributor,
64
+ edition: fetch_edition,
65
+ language: @tags["LA"].map(&:itself),
66
+ keyword: fetch_keyword,
67
+ source: fetch_source,
68
+ )
69
+ end
70
+
71
+ # @return [String, nil] the primary docidentifier's content
72
+ def self.record_key(item)
73
+ ids = Array(item.docidentifier)
74
+ primary = (ids.find(&:primary) || ids.first)&.content.to_s
75
+ primary unless primary.empty?
76
+ end
77
+
78
+ private
79
+
80
+ def entry_type
81
+ REVERSE_ENTRY_TYPES.fetch(@tags["TY"].first, "standard")
82
+ end
83
+
84
+ def fetch_docid
85
+ @tags["ID"].map { |v| Docidentifier.new(content: v, primary: true) }
86
+ end
87
+
88
+ def fetch_title
89
+ @tags["TI"].map { |v| Title.new(type: "title-main", content: v) }
90
+ end
91
+
92
+ # RIS dates are "YYYY" or "YYYY/MM/DD".
93
+ def fetch_date
94
+ @tags["PY"].map do |v|
95
+ on = v.match?(/\A\d{4}\z/) ? v : (::Date.parse(v.tr("/", "-")).to_s rescue v)
96
+ Bib::Date.new(type: "published", at: on)
97
+ end
98
+ end
99
+
100
+ # The renderer emits "Surname, Forename" for persons and a bare
101
+ # name for organizations under the same AU tag; a comma splits a
102
+ # person, a bare token is an organization name.
103
+ def fetch_contributor # rubocop:disable Metrics/AbcSize
104
+ contribs = []
105
+ @tags["AU"].each do |name|
106
+ contribs << if name.include?(",")
107
+ person_contributor(name)
108
+ else
109
+ org_contributor(name, "author")
110
+ end
111
+ end
112
+ @tags["PB"].each { |name| contribs << org_contributor(name, "publisher") }
113
+ contribs
114
+ end
115
+
116
+ def person_contributor(name)
117
+ parts = name.split(", ")
118
+ surname = LocalizedString.new(content: parts.first)
119
+ forename = (parts[1] || "").split.map { |fn| FullNameType::Forename.new(content: fn) }
120
+ person = Person.new(name: FullName.new(surname: surname, forename: forename))
121
+ Contributor.new(person: person, role: [Contributor::Role.new(type: "author")])
122
+ end
123
+
124
+ def org_contributor(name, role)
125
+ org = Organization.new(name: [TypedLocalizedString.new(content: name)])
126
+ Contributor.new(organization: org, role: [Contributor::Role.new(type: role)])
127
+ end
128
+
129
+ def fetch_edition
130
+ Edition.new(content: @tags["ET"].first.to_s) if @tags["ET"].any?
131
+ end
132
+
133
+ def fetch_keyword
134
+ @tags["KW"].map { |v| Keyword.new(vocab: LocalizedString.new(content: v)) }
135
+ end
136
+
137
+ def fetch_source
138
+ @tags["UR"].map { |v| Uri.new(type: "src", content: v) }
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Relaton
4
+ module Bib
5
+ module Converter
6
+ module Ris
7
+ class ToRis
8
+ def initialize(item)
9
+ @item = item
10
+ end
11
+
12
+ # @return [String]
13
+ def to_s
14
+ lines = ["TY - #{ENTRY_TYPES[@item.type.to_s] || 'STD'}"]
15
+ add_authors(lines)
16
+ add_field(lines, "TI", primary_title)
17
+ add_field(lines, "ID", primary_docid)
18
+ add_field(lines, "PY", published_year)
19
+ add_field(lines, "ET", @item.edition&.to_s)
20
+ lang = Array(@item.language).first
21
+ add_field(lines, "LA", lang.to_s)
22
+ Array(@item.keyword).each { |k| add_field(lines, "KW", k.content.to_s) }
23
+ add_field(lines, "UR", source_uri)
24
+ lines << "ER - "
25
+ lines.join("\r\n") + "\r\n"
26
+ end
27
+
28
+ private
29
+
30
+ def add_field(lines, tag, value)
31
+ lines << "#{tag} - #{value}" if value && !value.empty?
32
+ end
33
+
34
+ def add_authors(lines)
35
+ Array(@item.contributor).each do |c|
36
+ roles = Array(c.role).map(&:type).compact
37
+ authorish = (roles & %w[author performer editor]).any?
38
+ publisher = roles.include?("publisher")
39
+ if authorish && c.person
40
+ out = person_display_name(c.person.name)
41
+ lines << "AU - #{out}" unless out.empty?
42
+ elsif authorish && c.organization
43
+ out = org_name(c.organization)
44
+ lines << "AU - #{out}" unless out.empty?
45
+ elsif publisher && c.organization
46
+ out = org_name(c.organization)
47
+ lines << "PB - #{out}" unless out.empty? || lines.any? { |l| l.start_with?("PB - ") }
48
+ end
49
+ end
50
+ end
51
+
52
+ def person_display_name(name)
53
+ return "" unless name
54
+
55
+ fore = Array(name.forename).map { |f| f.respond_to?(:content) ? f.content.to_s : f.to_s }.join(" ")
56
+ sur = name.surname.respond_to?(:content) ? name.surname.content.to_s : name.surname.to_s
57
+ complete = name.completename.respond_to?(:content) ? name.completename.content.to_s : name.completename.to_s
58
+ return "#{sur}, #{fore}" unless fore.empty? || sur.empty?
59
+ return sur unless sur.empty?
60
+
61
+ complete
62
+ end
63
+
64
+ def org_name(org)
65
+ name = Array(org.name).map { |n| n.respond_to?(:content) ? n.content.to_s : n.to_s }.find(&:itself)
66
+ name || org.abbreviation.to_s
67
+ end
68
+
69
+ def primary_title
70
+ Titles.of(@item)
71
+ end
72
+
73
+ def primary_docid
74
+ ids = Array(@item.docidentifier)
75
+ (ids.find(&:primary) || ids.first)&.content.to_s
76
+ end
77
+
78
+ def published_year
79
+ date = Array(@item.date).find { |d| %w[published issued].include?(d.type.to_s) } || @item.date.first
80
+ value = date && (date.at || date.from || date.to)
81
+ value.to_s[/\d{4}/]
82
+ end
83
+
84
+ def source_uri
85
+ Array(@item.source).map { |s| s.respond_to?(:content) ? s.content.to_s : s.to_s }
86
+ .find { |u| u.start_with?("http") }
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "ris/from_ris"
4
+ require_relative "ris/to_ris"
3
5
 
4
6
  module Relaton
5
7
  module Bib
@@ -13,90 +15,14 @@ module Relaton
13
15
  "thesis" => "THES", "website" => "ELEC", "webresource" => "ELEC",
14
16
  }.freeze
15
17
 
18
+ # ItemData -> RIS string
16
19
  def self.from_item(item)
17
- Renderer.new(item).to_s
20
+ ToRis.new(item).to_s
18
21
  end
19
22
 
20
- class Renderer
21
- def initialize(item)
22
- @item = item
23
- end
24
-
25
- def to_s
26
- lines = ["TY - #{ENTRY_TYPES[@item.type.to_s] || 'STD'}"]
27
- add_authors(lines)
28
- add_field(lines, "TI", primary_title)
29
- add_field(lines, "ID", primary_docid)
30
- add_field(lines, "PY", published_year)
31
- add_field(lines, "ET", @item.edition&.to_s)
32
- lang = Array(@item.language).first
33
- add_field(lines, "LA", lang.to_s)
34
- Array(@item.keyword).each { |k| add_field(lines, "KW", k.content.to_s) }
35
- add_field(lines, "UR", source_uri)
36
- lines << "ER - "
37
- lines.join("\r\n") + "\r\n"
38
- end
39
-
40
- private
41
-
42
- def add_field(lines, tag, value)
43
- lines << "#{tag} - #{value}" if value && !value.empty?
44
- end
45
-
46
- def add_authors(lines)
47
- Array(@item.contributor).each do |c|
48
- roles = Array(c.role).map(&:type).compact
49
- authorish = (roles & %w[author performer editor]).any?
50
- publisher = roles.include?("publisher")
51
- if authorish && c.person
52
- out = person_display_name(c.person.name)
53
- lines << "AU - #{out}" unless out.empty?
54
- elsif authorish && c.organization
55
- out = org_name(c.organization)
56
- lines << "AU - #{out}" unless out.empty?
57
- elsif publisher && c.organization
58
- out = org_name(c.organization)
59
- lines << "PB - #{out}" unless out.empty? || lines.any? { |l| l.start_with?("PB - ") }
60
- end
61
- end
62
- end
63
-
64
- def person_display_name(name)
65
- return "" unless name
66
-
67
- fore = Array(name.forename).map { |f| f.respond_to?(:content) ? f.content.to_s : f.to_s }.join(" ")
68
- sur = name.surname.respond_to?(:content) ? name.surname.content.to_s : name.surname.to_s
69
- complete = name.completename.respond_to?(:content) ? name.completename.content.to_s : name.completename.to_s
70
- return "#{sur}, #{fore}" unless fore.empty? || sur.empty?
71
- return sur unless sur.empty?
72
-
73
- complete
74
- end
75
-
76
- def org_name(org)
77
- name = Array(org.name).map { |n| n.respond_to?(:content) ? n.content.to_s : n.to_s }.find(&:itself)
78
- name || org.abbreviation.to_s
79
- end
80
-
81
- def primary_title
82
- Titles.of(@item)
83
- end
84
-
85
- def primary_docid
86
- ids = Array(@item.docidentifier)
87
- (ids.find(&:primary) || ids.first)&.content.to_s
88
- end
89
-
90
- def published_year
91
- date = Array(@item.date).find { |d| %w[published issued].include?(d.type.to_s) } || @item.date.first
92
- value = date && (date.at || date.from || date.to)
93
- value.to_s[/\d{4}/]
94
- end
95
-
96
- def source_uri
97
- Array(@item.source).map { |s| s.respond_to?(:content) ? s.content.to_s : s.to_s }
98
- .find { |u| u.start_with?("http") }
99
- end
23
+ # RIS string -> Hash{String=>ItemData}
24
+ def self.to_item(ris_str)
25
+ FromRis.parse(ris_str)
100
26
  end
101
27
  end
102
28
  end
@@ -166,6 +166,10 @@ module Relaton
166
166
  Converter::Ris.from_item(self)
167
167
  end
168
168
 
169
+ def to_endnote
170
+ Converter::Endnote.from_item(self)
171
+ end
172
+
169
173
  def to_csl_json
170
174
  Converter::Csl.from_item(self)
171
175
  end
data/lib/relaton/bib.rb CHANGED
@@ -25,6 +25,7 @@ module Relaton
25
25
  module Bib
26
26
  module Converter
27
27
  autoload :Ris, "relaton/bib/converter/ris"
28
+ autoload :Endnote, "relaton/bib/converter/endnote"
28
29
  autoload :Csl, "relaton/bib/converter/csl"
29
30
  autoload :Titles, "relaton/bib/converter/titles"
30
31
  end
@@ -82,7 +82,10 @@ module Relaton
82
82
  # @return [Relaton::Bibdata, Relaton::Bibcollection]
83
83
  def new_bib_item_class(item)
84
84
  if item.is_a?(Hash)
85
- if item["items"]
85
+ # `#to_h` writes a nested collection as `{"root" => …}`.
86
+ if item["root"].is_a?(Hash)
87
+ ::Relaton::Bibcollection.new(item["root"])
88
+ elsif item["items"]
86
89
  ::Relaton::Bibcollection.new(item)
87
90
  else
88
91
  bibitem = ::Relaton::Cli::YAMLConvertor.convert_single_file item