relaton-bib 1.2.4 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ubuntu.yml +1 -0
  3. data/.rubocop.yml +2 -2
  4. data/README.adoc +16 -0
  5. data/lib/relaton_bib.rb +2 -5
  6. data/lib/relaton_bib/bib_item_locality.rb +13 -1
  7. data/lib/relaton_bib/biblio_note.rb +11 -0
  8. data/lib/relaton_bib/biblio_version.rb +12 -0
  9. data/lib/relaton_bib/bibliographic_date.rb +13 -0
  10. data/lib/relaton_bib/bibliographic_item.rb +80 -24
  11. data/lib/relaton_bib/classification.rb +11 -0
  12. data/lib/relaton_bib/contribution_info.rb +27 -1
  13. data/lib/relaton_bib/contributor.rb +55 -1
  14. data/lib/relaton_bib/copyright_association.rb +14 -1
  15. data/lib/relaton_bib/document_identifier.rb +20 -4
  16. data/lib/relaton_bib/document_relation.rb +14 -4
  17. data/lib/relaton_bib/document_relation_collection.rb +12 -0
  18. data/lib/relaton_bib/document_status.rb +10 -0
  19. data/lib/relaton_bib/editorial_group.rb +9 -0
  20. data/lib/relaton_bib/formatted_ref.rb +7 -0
  21. data/lib/relaton_bib/formatted_string.rb +11 -0
  22. data/lib/relaton_bib/hash_converter.rb +38 -30
  23. data/lib/relaton_bib/ics.rb +11 -0
  24. data/lib/relaton_bib/localized_string.rb +23 -6
  25. data/lib/relaton_bib/medium.rb +11 -0
  26. data/lib/relaton_bib/organization.rb +27 -7
  27. data/lib/relaton_bib/person.rb +53 -7
  28. data/lib/relaton_bib/place.rb +13 -1
  29. data/lib/relaton_bib/series.rb +25 -4
  30. data/lib/relaton_bib/structured_identifier.rb +30 -0
  31. data/lib/relaton_bib/technical_committee.rb +11 -0
  32. data/lib/relaton_bib/typed_title_string.rb +13 -7
  33. data/lib/relaton_bib/typed_uri.rb +11 -0
  34. data/lib/relaton_bib/validity.rb +11 -0
  35. data/lib/relaton_bib/version.rb +1 -1
  36. data/lib/relaton_bib/workgroup.rb +10 -0
  37. data/lib/relaton_bib/xml_parser.rb +53 -38
  38. metadata +2 -2
@@ -29,5 +29,16 @@ module RelatonBib
29
29
  hash["scale"] = scale if scale
30
30
  hash
31
31
  end
32
+
33
+ # @param prefix [String]
34
+ # @return [String]
35
+ def to_asciibib(prefix = "")
36
+ pref = prefix.empty? ? "medium." : prefix + ".medium."
37
+ out = ""
38
+ out += "#{pref}form:: #{form}\n" if form
39
+ out += "#{pref}size:: #{size}\n" if size
40
+ out += "#{pref}scale:: #{scale}\n" if scale
41
+ out
42
+ end
32
43
  end
33
44
  end
@@ -3,11 +3,6 @@
3
3
  require "relaton_bib/contributor"
4
4
 
5
5
  module RelatonBib
6
- # module OrgIdentifierType
7
- # ORCID = 'orcid'
8
- # URI = 'uri'
9
- # end
10
-
11
6
  # Organization identifier.
12
7
  class OrgIdentifier
13
8
  ORCID = "orcid"
@@ -39,6 +34,17 @@ module RelatonBib
39
34
  def to_hash
40
35
  { "type" => type, "id" => value }
41
36
  end
37
+
38
+ # @param prefix [String]
39
+ # @param count [Integer]
40
+ # @return [String]
41
+ def to_asciibib(prefix = "", count = 1)
42
+ pref = prefix.empty? ? prefix : prefix + "."
43
+ out = count > 1 ? "#{pref}identifier::\m" : ""
44
+ out += "#{pref}identifier.type:: #{type}\n"
45
+ out += "#{pref}identifier.value:: #{value}\n"
46
+ out
47
+ end
42
48
  end
43
49
 
44
50
  # Organization.
@@ -61,7 +67,7 @@ module RelatonBib
61
67
  # @param url [String]
62
68
  # @param identifier [Array<RelatonBib::OrgIdentifier>]
63
69
  # @param contact [Array<RelatonBib::Address, RelatonBib::Contact>]
64
- def initialize(**args)
70
+ def initialize(**args) # rubocop:disable Metrics/AbcSize
65
71
  raise ArgumentError, "missing keyword: name" unless args[:name]
66
72
 
67
73
  super(url: args[:url], contact: args.fetch(:contact, []))
@@ -78,7 +84,7 @@ module RelatonBib
78
84
  end
79
85
 
80
86
  # @param builder [Nokogiri::XML::Builder]
81
- def to_xml(builder)
87
+ def to_xml(builder) # rubocop:disable Metrics/AbcSize
82
88
  builder.organization do
83
89
  name.each do |n|
84
90
  builder.name { |b| n.to_xml b }
@@ -100,6 +106,20 @@ module RelatonBib
100
106
  { "organization" => hash.merge(super) }
101
107
  end
102
108
 
109
+ # @param prefix [String]
110
+ # @param count [Integer]
111
+ # @return [String]
112
+ def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
113
+ pref = prefix.sub /\*$/, "organization"
114
+ out = count > 1 ? "#{pref}::\m" : ""
115
+ name.each { |n| out += n.to_asciibib "#{pref}.name", name.size }
116
+ out += abbreviation.to_asciibib "#{pref}.abbreviation" if abbreviation
117
+ out += subdivision.to_asciibib "#{pref}.subdivision" if subdivision
118
+ identifier.each { |n| out += n.to_asciibib pref, identifier.size }
119
+ out += super pref
120
+ out
121
+ end
122
+
103
123
  private
104
124
 
105
125
  # @param arg [String, Hash, RelatoBib::LocalizedString]
@@ -45,12 +45,12 @@ module RelatonBib
45
45
  end
46
46
 
47
47
  # @param builder [Nokogiri::XML::Builder]
48
- def to_xml(builder)
48
+ def to_xml(builder) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
49
49
  builder.name do
50
50
  if completename
51
51
  builder.completename { completename.to_xml builder }
52
52
  else
53
- prefix.each { |p| builder.prefix { p.to_xml builder } }
53
+ prefix.each { |p| builder.prefix { p.to_xml builder } }
54
54
  forename.each { |f| builder.forename { f.to_xml builder } }
55
55
  initial.each { |i| builder.initial { i.to_xml builder } }
56
56
  builder.surname { surname.to_xml builder }
@@ -60,7 +60,7 @@ module RelatonBib
60
60
  end
61
61
 
62
62
  # @return [Hash]
63
- def to_hash
63
+ def to_hash # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
64
64
  hash = {}
65
65
  hash["forename"] = single_element_array(forename) if forename&.any?
66
66
  hash["initial"] = single_element_array(initial) if initial&.any?
@@ -70,6 +70,23 @@ module RelatonBib
70
70
  hash["completename"] = completename.to_hash if completename
71
71
  hash
72
72
  end
73
+
74
+ # @param pref [String]
75
+ # @return [String]
76
+ def to_asciibib(pref) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
77
+ prf = pref.empty? ? pref : pref + "."
78
+ out = forename.map do |fn|
79
+ fn.to_asciibib "#{prf}forename", forename.size
80
+ end.join
81
+ initial.each { |i| out += i.to_asciibib "#{prf}initial", initial.size }
82
+ out += surname.to_asciibib "#{prf}surname" if surname
83
+ addition.each do |ad|
84
+ out += ad.to_asciibib "#{prf}addition", addition.size
85
+ end
86
+ prefix.each { |pr| out += pr.to_asciibib "#{prf}prefix", prefix.size }
87
+ out += completename.to_asciibib "#{prf}completename" if completename
88
+ out
89
+ end
73
90
  end
74
91
 
75
92
  # Person identifier type.
@@ -89,13 +106,15 @@ module RelatonBib
89
106
 
90
107
  # Person identifier.
91
108
  class PersonIdentifier
92
- # @return [RelatonBib::PersonIdentifierType::ISNI, RelatonBib::PersonIdentifierType::URI]
109
+ # @return [RelatonBib::PersonIdentifierType::ISNI,
110
+ # RelatonBib::PersonIdentifierType::URI]
93
111
  attr_accessor :type
94
112
 
95
113
  # @return [String]
96
114
  attr_accessor :value
97
115
 
98
- # @param type [RelatonBib::PersonIdentifierType::ISNI, RelatonBib::PersonIdentifierType::URI]
116
+ # @param type [RelatonBib::PersonIdentifierType::ISNI,
117
+ # RelatonBib::PersonIdentifierType::URI]
99
118
  # @param value [String]
100
119
  def initialize(type, value)
101
120
  PersonIdentifierType.check type
@@ -113,6 +132,17 @@ module RelatonBib
113
132
  def to_hash
114
133
  { "type" => type, "id" => value }
115
134
  end
135
+
136
+ # @param prefix [String]
137
+ # @param count [Integer] number of ids
138
+ # @return [String]
139
+ def to_asciibib(prefix = "", count = 1)
140
+ pref = prefix.empty? ? prefix : prefix + "."
141
+ out = count > 1 ? "#{prefix}::\n" : ""
142
+ out += "#{pref}type:: #{type}\n"
143
+ out += "#{pref}value:: #{value}\n"
144
+ out
145
+ end
116
146
  end
117
147
 
118
148
  # Person class.
@@ -131,7 +161,8 @@ module RelatonBib
131
161
  # @param contact [Array<RelatonBib::Address, RelatonBib::Contact>]
132
162
  # @param identifier [Array<RelatonBib::PersonIdentifier>]
133
163
  # @param url [String, NilClass]
134
- def initialize(name:, affiliation: [], contact: [], identifier: [], url: nil)
164
+ def initialize(name:, affiliation: [], contact: [], identifier: [],
165
+ url: nil)
135
166
  super(contact: contact, url: url)
136
167
  @name = name
137
168
  @affiliation = affiliation
@@ -151,9 +182,24 @@ module RelatonBib
151
182
  # @return [Hash]
152
183
  def to_hash
153
184
  hash = { "name" => name.to_hash }
154
- hash["affiliation"] = single_element_array(affiliation) if affiliation&.any?
185
+ if affiliation&.any?
186
+ hash["affiliation"] = single_element_array(affiliation)
187
+ end
155
188
  hash["identifier"] = single_element_array(identifier) if identifier&.any?
156
189
  { "person" => hash.merge(super) }
157
190
  end
191
+
192
+ # @param prefix [String]
193
+ # @count [Integer] number of persons
194
+ # @return [String]
195
+ def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize
196
+ pref = prefix.sub /\*$/, "person"
197
+ out = count > 1 ? "#{pref}::\n" : ""
198
+ out += name.to_asciibib pref
199
+ affiliation.each { |af| out += af.to_asciibib pref, affiliation.size }
200
+ identifier.each { |id| out += id.to_asciibib pref, identifier.size }
201
+ out += super pref
202
+ out
203
+ end
158
204
  end
159
205
  end
@@ -33,5 +33,17 @@ module RelatonBib
33
33
  name
34
34
  end
35
35
  end
36
+
37
+ # @param prefix [String]
38
+ # @param count [Integer] number of places
39
+ # @return [Stirng]
40
+ def to_asciibib(prefix = "", count = 1)
41
+ pref = prefix.empty? ? "place" : prefix + ".place"
42
+ out = count > 1 ? "#{pref}::\n" : ""
43
+ out += "#{pref}.name:: #{name}\n"
44
+ out += "#{pref}.uri:: #{uri}\n" if uri
45
+ out += "#{pref}.region:: #{region}\n" if region
46
+ out
47
+ end
36
48
  end
37
- end
49
+ end
@@ -39,7 +39,8 @@ module RelatonBib
39
39
 
40
40
  # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
41
41
 
42
- # @param type [String, NilClass] title or formattedref argument should be passed
42
+ # @param type [String, NilClass] title or formattedref argument should be
43
+ # passed
43
44
  # @param formattedref [RelatonBib::FormattedRef, NilClass]
44
45
  # @param title [RelatonBib::TypedTitleString, NilClass]
45
46
  # @param place [String, NilClass]
@@ -50,7 +51,8 @@ module RelatonBib
50
51
  # @param number [String, NilClass]
51
52
  # @param partnumber [String, NilClass]
52
53
  def initialize(**args)
53
- unless args[:title].is_a?(RelatonBib::TypedTitleString) || args[:formattedref]
54
+ unless args[:title].is_a?(RelatonBib::TypedTitleString) ||
55
+ args[:formattedref]
54
56
  raise ArgumentError, "argument `title` or `formattedref` should present"
55
57
  end
56
58
 
@@ -74,7 +76,7 @@ module RelatonBib
74
76
  # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
75
77
 
76
78
  # @param builder [Nokogiri::XML::Builder]
77
- def to_xml(builder)
79
+ def to_xml(builder) # rubocop:disable Metrics/MethodLength
78
80
  xml = builder.series do
79
81
  if formattedref
80
82
  formattedref.to_xml builder
@@ -95,7 +97,7 @@ module RelatonBib
95
97
  # rubocop:enable Metrics/PerceivedComplexity
96
98
 
97
99
  # @return [Hash]
98
- def to_hash
100
+ def to_hash # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
99
101
  hash = {}
100
102
  hash["type"] = type if type
101
103
  hash["formattedref"] = formattedref.to_hash if formattedref
@@ -109,5 +111,24 @@ module RelatonBib
109
111
  hash["partnumber"] = partnumber if partnumber
110
112
  hash
111
113
  end
114
+
115
+ # @param prefix [String]
116
+ # @param count [Integer]
117
+ # @return [String]
118
+ def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength,Metrics/PerceivedComplexity
119
+ pref = prefix.empty? ? "series" : prefix + ".series"
120
+ out = count > 1 ? "#{pref}::\n" : ""
121
+ out += "#{pref}.type:: #{type}\n" if type
122
+ out += formattedref.to_asciibib pref if formattedref
123
+ out += title.to_asciibib pref if title
124
+ out += "#{pref}.place:: #{place}\n" if place
125
+ out += "#{pref}.organization:: #{organization}\n" if organization
126
+ out += abbreviation.to_asciibib "#{pref}.abbreviation" if abbreviation
127
+ out += "#{pref}.from:: #{from}\n" if from
128
+ out += "#{pref}.to:: #{to}\n" if to
129
+ out += "#{pref}.number:: #{number}\n" if number
130
+ out += "#{pref}.partnumber:: #{partnumber}\n" if partnumber
131
+ out
132
+ end
112
133
  end
113
134
  end
@@ -20,6 +20,17 @@ module RelatonBib
20
20
  single_element_array @collection
21
21
  end
22
22
 
23
+ # @param prefix [String]
24
+ # @return [String]
25
+ def to_asciibib(prefix = "")
26
+ pref = prefix.empty? ? prefix : prefix + "."
27
+ pref += "structured_identifier"
28
+ @collection.reduce("") do |out, si|
29
+ out += "#{pref}::\n" if @collection.size > 1
30
+ out + si.to_asciibib(pref)
31
+ end
32
+ end
33
+
23
34
  # remoe year from docnumber
24
35
  def remove_date
25
36
  @collection.each &:remove_date
@@ -119,6 +130,25 @@ module RelatonBib
119
130
  end
120
131
  # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
121
132
 
133
+ # @param prefix [String]
134
+ # @return [String]
135
+ def to_asciibib(prefix) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength,Metrics/PerceivedComplexity
136
+ out = "#{prefix}.docnumber:: #{docnumber}\n"
137
+ agency.each { |a| out += "#{prefix}.agency:: #{a}\n" }
138
+ out += "#{prefix}.type:: #{type}\n" if type
139
+ out += "#{prefix}.class:: #{klass}\n" if klass
140
+ out += "#{prefix}.partnumber:: #{partnumber}\n" if partnumber
141
+ out += "#{prefix}.edition:: #{edition}\n" if edition
142
+ out += "#{prefix}.version:: #{version}\n" if version
143
+ out += "#{prefix}.supplementtype:: #{supplementtype}\n" if supplementtype
144
+ if supplementnumber
145
+ out += "#{prefix}.supplementnumber:: #{supplementnumber}\n"
146
+ end
147
+ out += "#{prefix}.language:: #{language}\n" if language
148
+ out += "#{prefix}.year:: #{year}\n" if year
149
+ out
150
+ end
151
+
122
152
  def remove_date
123
153
  if @type == "Chinese Standard"
124
154
  @docnumber.sub!(/-[12]\d\d\d/, "")
@@ -21,5 +21,16 @@ module RelatonBib
21
21
  def to_hash
22
22
  workgroup.to_hash
23
23
  end
24
+
25
+ # @param prefix [String]
26
+ # @param count [Integer] number of technical committees
27
+ # @return [String]
28
+ def to_asciibib(prefix = "", count = 1)
29
+ pref = prefix.empty? ? prefix : prefix + "."
30
+ pref += "technical_committee"
31
+ out = count > 1 ? "#{pref}::\n" : ""
32
+ out += workgroup.to_asciibib pref
33
+ out
34
+ end
24
35
  end
25
36
  end
@@ -6,14 +6,12 @@ module RelatonBib
6
6
  # @return [RelatonBib::FormattedString]
7
7
  attr_reader :title
8
8
 
9
- # rubocop:disable Metrics/MethodLength
10
-
11
9
  # @param type [String]
12
10
  # @param title [RelatonBib::FormattedString, Hash]
13
11
  # @param content [String]
14
12
  # @param language [String]
15
13
  # @param script [String]
16
- def initialize(**args)
14
+ def initialize(**args) # rubocop:disable Metrics/MethodLength
17
15
  unless args[:title] || args[:content]
18
16
  raise ArgumentError, %{Keyword "title" or "content" should be passed.}
19
17
  end
@@ -29,7 +27,6 @@ module RelatonBib
29
27
  @title = FormattedString.new(fsargs)
30
28
  end
31
29
  end
32
- # rubocop:enable Metrics/MethodLength
33
30
 
34
31
  # @param title [String]
35
32
  # @return [Array<self>]
@@ -50,15 +47,13 @@ module RelatonBib
50
47
  case ttls.size
51
48
  when 0, 1 then [nil, ttls.first.to_s, nil]
52
49
  else intro_or_part ttls
53
- # when 2, 3 then intro_or_part ttls
54
- # else [ttls[0], ttls[1], ttls[2..-1].join(" -- ")]
55
50
  end
56
51
  end
57
52
 
58
53
  # @param ttls [Array<String>]
59
54
  # @return [Array<Strin, nil>]
60
55
  def self.intro_or_part(ttls)
61
- if /^(Part|Partie) \d+:/ =~ ttls[1]
56
+ if /^(Part|Partie) \d+:/.match? ttls[1]
62
57
  [nil, ttls[0], ttls[1..-1].join(" -- ")]
63
58
  else
64
59
  parts = ttls.slice(2..-1)
@@ -86,5 +81,16 @@ module RelatonBib
86
81
  end
87
82
  hash
88
83
  end
84
+
85
+ # @param prefix [String]
86
+ # @param count [Integer] number of titles
87
+ # @return [String]
88
+ def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize
89
+ pref = prefix.empty? ? prefix : prefix + "."
90
+ out = count > 1 ? "#{pref}title::\n" : ""
91
+ out += "#{pref}title.type:: #{type}\n" if type
92
+ out += title.to_asciibib "#{pref}title"
93
+ out
94
+ end
89
95
  end
90
96
  end
@@ -32,5 +32,16 @@ module RelatonBib
32
32
  hash["type"] = type.to_s if type
33
33
  hash
34
34
  end
35
+
36
+ # @param prefix [String]
37
+ # @param count [Integer] number of links
38
+ # @return [String]
39
+ def to_asciibib(prefix = "", count = 1)
40
+ pref = prefix.empty? ? "link" : prefix + ".link"
41
+ out = count > 1 ? "#{pref}::\n" : ""
42
+ out += "#{pref}.type:: #{type}\n" if type
43
+ out += "#{pref}.content:: #{content}\n"
44
+ out
45
+ end
35
46
  end
36
47
  end
@@ -37,5 +37,16 @@ module RelatonBib
37
37
  hash["revision"] = revision.strftime(FORMAT) if revision
38
38
  hash
39
39
  end
40
+
41
+ # @param prefix [String]
42
+ # @return [String]
43
+ def to_asciibib(prefix = "")
44
+ pref = prefix.empty? ? "validity." : prefix + ".validity."
45
+ out = ""
46
+ out += "#{pref}begins:: #{begins.strftime(FORMAT)}\n" if begins
47
+ out += "#{pref}ends:: #{ends.strftime(FORMAT)}\n" if ends
48
+ out += "#{pref}revision:: #{revision.strftime(FORMAT)}\n" if revision
49
+ out
50
+ end
40
51
  end
41
52
  end
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.2.4".freeze
2
+ VERSION = "1.3.0".freeze
3
3
  end
@@ -32,5 +32,15 @@ module RelatonBib
32
32
  hash["type"] = type if type
33
33
  hash
34
34
  end
35
+
36
+ # @param prefix [String]
37
+ # @return [String]
38
+ def to_asciibib(prefix = "")
39
+ pref = prefix.empty? ? prefix : prefix + "."
40
+ out = "#{pref}content:: #{content}\n"
41
+ out += "#{pref}number:: #{number}\n" if number
42
+ out += "#{pref}type:: #{type}\n" if type
43
+ out
44
+ end
35
45
  end
36
46
  end