iso-bib-item 0.1.6 → 0.1.7

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
- SHA256:
3
- metadata.gz: 186fc45016ad7f72189281554e2fe4a195145ad7765e8718565a4b8fe4d70dfb
4
- data.tar.gz: 1416aee5aa32dd0fc815f0055e30c3cccb6690744fa212dfe6bc2587e797adc0
2
+ SHA1:
3
+ metadata.gz: 28b47902774baa20582877c3f4bb40b511858665
4
+ data.tar.gz: 0b91cba1d8b30a5b725ef4cb5c6945ac17fdc197
5
5
  SHA512:
6
- metadata.gz: 186f877bb88a117b1e1cca056c00cdd4bddfd3727e2de81a461d228298306e962b9b726fd16699c9a7c02a2bd42841a2330ce382c78088dec16b7a80747cd5df
7
- data.tar.gz: 6be1a5e689c6039f93e394449430d0eb678adc295c45488c25df87278f22e5e62fa753481d80b0cea29926d0a8139b6c33ad05e2274a9d2f10afe979f3ac0518
6
+ metadata.gz: 9fe3106f7ce849ad2f8687abb31c936ab782e9cb143c8a6cd94a0e276ace015fd9289bce6fb1426537dcd5aa9d0c2998c58087d7888252cbdcef23ca52e04bc4
7
+ data.tar.gz: 7a8de9331fa305198f6f63c04a93f913d34a276687dd9ff164d7575ef1648ce5900bd594d3b879d26fc6d198ec5abec633870eb3fa1b378471e4d57ebd9f087e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- iso-bib-item (0.1.6)
4
+ iso-bib-item (0.1.7)
5
5
  duplicate
6
6
  isoics (~> 0.1.6)
7
7
  nokogiri
data/lib/iso_bib_item.rb CHANGED
@@ -2,8 +2,3 @@
2
2
 
3
3
  require 'iso_bib_item/version'
4
4
  require 'iso_bib_item/iso_bibliographic_item'
5
-
6
- # ISO bibliographic model.
7
- # module IsoBibItem
8
- # # Your code goes here...
9
- # end
@@ -28,6 +28,10 @@ module IsoBibItem
28
28
  @to = Time.strptime(to, '%Y-%d') if to
29
29
  end
30
30
 
31
+ # rubocop:disable Metric/AbcSize
32
+
33
+ # @param builder [Nokogiri::XML::Builder]
34
+ # @return [Nokogiri::XML::Builder]
31
35
  def to_xml(builder, **opts)
32
36
  builder.date(type: type) do
33
37
  if on
@@ -38,5 +42,6 @@ module IsoBibItem
38
42
  end
39
43
  end
40
44
  end
45
+ # rubocop:enable Metric/AbcSize
41
46
  end
42
47
  end
@@ -83,6 +83,9 @@ module IsoBibItem
83
83
 
84
84
  # Bibliographic item
85
85
  class BibliographicItem
86
+ # @return [String]
87
+ attr_reader :id
88
+
86
89
  # @return [Array<IsoBibItem::FormattedString>]
87
90
  attr_reader :title
88
91
 
@@ -128,6 +131,11 @@ module IsoBibItem
128
131
  # @return [IsoBibItem::DocRelationCollection]
129
132
  attr_reader :relations
130
133
 
134
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
135
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
136
+
137
+ # @param id [Arrat<IsoBibItem::DocumentIdentifier>]
138
+ # @param title [Array<IsoBibItem::FormattedString>]
131
139
  # @param language [Arra<String>]
132
140
  # @param script [Array<String>]
133
141
  # @param dates [Array<Hash{type=>String, from=>String, to=>String}>]
@@ -136,14 +144,16 @@ module IsoBibItem
136
144
  # @param abstract [Array<Hash{content=>String, language=>String,
137
145
  # script=>String, type=>String}>]
138
146
  # @param relations [Array<Hash{type=>String, identifier=>String}>]
139
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
140
147
  def initialize(**args)
141
- @title = []
148
+ @id = args[:id]
149
+ @title = (args[:titles] || []).map { |t| FormattedString.new t }
142
150
  @docidentifier = []
143
- @dates = (args[:dates] || []).map { |d| BibliographicDate.new(d) }
144
- @contributors = (args[:contributors] || []).map do |c|
145
- ContributionInfo.new(entity: Organization.new(c[:entity]),
146
- role: c[:roles])
151
+ @dates = (args[:dates] || []).map do |d|
152
+ d.is_a?(Hash) ? BibliographicDate.new(d) : d
153
+ end
154
+ @contributors = (args[:contributors] || []).map do |c|
155
+ e = c[:entity].is_a?(Hash) ? Organization.new(c[:entity]) : c[:entity]
156
+ ContributionInfo.new(entity: e, role: c[:roles])
147
157
  end
148
158
  @notes = []
149
159
  @language = args[:language]
@@ -152,13 +162,10 @@ module IsoBibItem
152
162
  FormattedString.new(a)
153
163
  end
154
164
  @relations = DocRelationCollection.new(args[:relations] || [])
165
+ @source = args[:source].map { |s| TypedUri.new(s) }
155
166
  end
156
167
  # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
157
-
158
- # @param docid [DocumentIdentifier]
159
- # def add_docidentifier(docid)
160
- # @docidentifier << docid
161
- # end
168
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
162
169
 
163
170
  # @param lang [String] language code Iso639
164
171
  # @return [IsoBibItem::FormattedString, Array<IsoBibItem::FormattedString>]
@@ -169,5 +176,23 @@ module IsoBibItem
169
176
  @abstract
170
177
  end
171
178
  end
179
+
180
+ # @return [String]
181
+ def to_xml
182
+ Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
183
+ xml.bibitem(id: id) do
184
+ title.each { |t| xml.title { t.to_xml xml } }
185
+ source.each { |s| s.to_xml xml }
186
+ dates.each { |d| d.to_xml xml }
187
+ contributors.each do |c|
188
+ xml.contributor do
189
+ c.role.each { |r| r.to_xml xml }
190
+ c.to_xml xml
191
+ end
192
+ end
193
+ language.each { |l| xml.language l }
194
+ end
195
+ end.doc.root.to_xml
196
+ end
172
197
  end
173
198
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'iso_bib_item/person'
4
+
3
5
  # Isobib module
4
6
  module IsoBibItem
5
7
  # Contributor's role.
@@ -10,8 +12,9 @@ module IsoBibItem
10
12
  # @return [ContributorRoleType]
11
13
  attr_reader :type
12
14
 
13
- # @param type [ContributorRoleType] allowed types "author", "editor",
15
+ # @param type [String] allowed types "author", "editor",
14
16
  # "cartographer", "publisher"
17
+ # @param description [Array<String>]
15
18
  def initialize(type, description = [])
16
19
  @type = type
17
20
  @description = description.map { |d| FormattedString.new d }
@@ -20,9 +23,7 @@ module IsoBibItem
20
23
  def to_xml(builder)
21
24
  builder.role(type: type) do
22
25
  description.each do |d|
23
- builder.description do |desc|
24
- d.to_xml(desc)
25
- end
26
+ builder.description { |desc| d.to_xml(desc) }
26
27
  end
27
28
  end
28
29
  end
@@ -3,10 +3,66 @@
3
3
  require 'uri'
4
4
 
5
5
  module IsoBibItem
6
- # Contact method.
7
- class ContactMethod
8
- # @return [String] @todo TBD
9
- attr_reader :contact
6
+ # Address class.
7
+ class Address
8
+ # @return [Array<String>]
9
+ attr_reader :street
10
+
11
+ # @return [String]
12
+ attr_reader :city
13
+
14
+ # @return [String, NilClass]
15
+ attr_reader :state
16
+
17
+ # @return [String]
18
+ attr_reader :country
19
+
20
+ # @return [String, NilClass]
21
+ attr_reader :postcode
22
+
23
+ # @param street [Array<String>]
24
+ # @param city [String]
25
+ # @param state [String]
26
+ # @param country [String]
27
+ # @param postcode [String]
28
+ def initialize(street:, city:, state: nil, country:, postcode: nil)
29
+ @street = street
30
+ @city = city
31
+ @state = state
32
+ @country = country
33
+ @postcode = postcode
34
+ end
35
+
36
+ # @param builder [Nokogiri::XML::Document]
37
+ def to_xml(doc)
38
+ doc.address do
39
+ street.each { |str| doc.street str }
40
+ doc.city city
41
+ doc.state state if state
42
+ doc.country country
43
+ doc.postcode postcode if postcode
44
+ end
45
+ end
46
+ end
47
+
48
+ # Contact class.
49
+ class Contact
50
+ # @return [String] allowed "phone", "email" or "uri"
51
+ attr_reader :type
52
+
53
+ # @return [String]
54
+ attr_reader :value
55
+
56
+ # @param phone [String]
57
+ def initialize(type:, value:)
58
+ @type = type
59
+ @value = value
60
+ end
61
+
62
+ # @param builder [Nokogiri::XML::Document]
63
+ def to_xml(doc)
64
+ doc.send type, value
65
+ end
10
66
  end
11
67
 
12
68
  # Affilation.
@@ -25,6 +81,14 @@ module IsoBibItem
25
81
  @organization = organization
26
82
  @description = []
27
83
  end
84
+
85
+ def to_xml(builder)
86
+ builder.affilation do
87
+ builder.name { name.to_xml builder } if name
88
+ description.each { |d| builder.description { d.to_xml builder } }
89
+ organization.to_xml builder
90
+ end
91
+ end
28
92
  end
29
93
 
30
94
  # Contributor.
@@ -32,13 +96,14 @@ module IsoBibItem
32
96
  # @return [URI]
33
97
  attr_reader :uri
34
98
 
35
- # @return [Array<IsoBibItem::ContactMethod>]
99
+ # @return [Array<IsoBibItem::Address, IsoBibItem::Phone>]
36
100
  attr_reader :contacts
37
101
 
38
102
  # @param url [String]
39
- def initialize(url = nil)
103
+ # @param contacts [Array<IsoBibItem::Address, IsoBibItem::Phone>]
104
+ def initialize(url: nil, contacts: [])
40
105
  @uri = URI url if url
41
- @contacts = []
106
+ @contacts = contacts
42
107
  end
43
108
 
44
109
  # @return [String]
@@ -93,6 +93,7 @@ module IsoBibItem
93
93
  attr_reader :ics
94
94
 
95
95
  # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
96
+
96
97
  # @param docid [Hash{project_number=>Integer, part_number=>Integer}]
97
98
  # @param titles [Array<Hash{title_intro=>String, title_main=>String,
98
99
  # title_part=>String, language=>String, script=>String}>]
@@ -116,7 +117,9 @@ module IsoBibItem
116
117
  # @param relations [Array<Hash{type=>String, identifier=>String}>]
117
118
  def initialize(**args)
118
119
  super_args = args.select do |k|
119
- %i[language script dates abstract contributors relations].include? k
120
+ %i[
121
+ id language script dates abstract contributors relations source
122
+ ].include? k
120
123
  end
121
124
  super(super_args)
122
125
  @docidentifier = IsoDocumentId.new args[:docid]
@@ -126,10 +129,7 @@ module IsoBibItem
126
129
  @status = IsoDocumentStatus.new(args[:docstatus])
127
130
  @workgroup = IsoProjectGroup.new(args[:workgroup]) if args[:workgroup]
128
131
  @ics = args[:ics].map { |i| Ics.new(i) }
129
- if args[:copyright]
130
- @copyright = CopyrightAssociation.new(args[:copyright])
131
- end
132
- @source = args[:source].map { |s| TypedUri.new(s) }
132
+ @copyright = CopyrightAssociation.new args[:copyright] if args[:copyright]
133
133
  end
134
134
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
135
135
 
@@ -139,10 +139,11 @@ module IsoBibItem
139
139
  def to_all_parts
140
140
  me = Duplicate.duplicate(self)
141
141
  @relations << DocumentRelation.new(type: "partOf", identifier: nil, url: nil, bibitem: me)
142
- @title.each { |t| t.remove_part }
142
+
143
+ @title.each(&:remove_part)
143
144
  @abstract = []
144
145
  @docidentifier.remove_part
145
- @allParts = true
146
+ @all_parts = true
146
147
  end
147
148
 
148
149
  # convert ISO:yyyy reference to reference to most recent
@@ -211,7 +212,6 @@ module IsoBibItem
211
212
  idstr.strip
212
213
  end
213
214
 
214
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
215
215
  def render_xml(builder, **opts)
216
216
  builder.send(:bibitem, type: type, id: id) do
217
217
  title.each { |t| t.to_xml builder }
@@ -236,10 +236,9 @@ module IsoBibItem
236
236
  builder.note("ISO DATE: #{opts[:note]}", format: 'text/plain')
237
237
  end
238
238
  ics.each { |i| i.to_xml builder }
239
- builder.allParts "true" if @allParts
239
+ builder.allParts 'true' if @all_parts
240
240
  yield(builder) if block_given?
241
241
  end
242
242
  end
243
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
244
243
  end
245
244
  end
@@ -23,13 +23,14 @@ module IsoBibItem
23
23
  # @param title_part [String]
24
24
  # @param language [String] language Iso639 code
25
25
  # @param script [String] script Iso15924 code
26
- def initialize(title_intro:, title_main:, title_part: nil, language:, script:)
26
+ def initialize(title_intro:, title_main:, title_part: nil, language:,
27
+ script:)
27
28
  @title_intro = title_intro
28
29
  @title_main = title_main
29
30
  @title_part = title_part
30
31
  @language = language
31
32
  @script = script
32
- @title_main = "[ -- ]" if @title_main.nil? || @title_main.empty?
33
+ @title_main = '[ -- ]' if @title_main.nil? || @title_main.empty?
33
34
  # "[ -- ]" # title cannot be nil
34
35
  end
35
36
 
@@ -43,7 +43,7 @@ module IsoBibItem
43
43
  # @param abbreviation [String]
44
44
  # @param url [String]
45
45
  def initialize(name:, abbreviation: nil, url: nil)
46
- super(url)
46
+ super(url: url)
47
47
  @name = LocalizedString.new name
48
48
  @abbreviation = LocalizedString.new abbreviation
49
49
  @identifiers = []
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'iso_bib_item/contributor'
2
4
 
3
5
  module IsoBibItem
@@ -6,30 +8,57 @@ module IsoBibItem
6
8
  # @return [Array<IsoBibItem::LocalizedString>]
7
9
  attr_accessor :forenames
8
10
 
9
- # @return [Array<IsoBibItem::LocalizedString]
10
- attr_accessor :inials
11
+ # @return [Array<IsoBibItem::LocalizedString>]
12
+ attr_accessor :initials
11
13
 
12
14
  # @return [IsoBibItem::LocalizedString]
13
15
  attr_accessor :surname
14
16
 
15
- # @return [Array<IsoBibItem::LocalizedString]
17
+ # @return [Array<IsoBibItem::LocalizedString>]
16
18
  attr_accessor :additions
17
19
 
18
- # @return [Array<IsoBibItem::LocalizedString]
20
+ # @return [Array<IsoBibItem::LocalizedString>]
19
21
  attr_accessor :prefix
20
22
 
21
- def initialize(surname)
22
- @surname = surname
23
- @forenames = []
24
- @initials = []
25
- @additions = []
26
- @prefix = []
23
+ # @return [IsoBibItem::LocalizedString]
24
+ attr_reader :completename
25
+
26
+ # @param surname [IsoBibItem::LocalizedString]
27
+ # @param forenames [Array<IsoBibItem::LocalizedString>]
28
+ # @param initials [Array<IsoBibItem::LocalizedString>]
29
+ # @param prefix [Array<IsoBibItem::LocalizedString>]
30
+ # @param completename [IsoBibItem::LocalizedString]
31
+ def initialize(**args)
32
+ unless args[:surname] || args[:completename]
33
+ raise ArgumentError, 'Should be given :surname or :completename'
34
+ end
35
+ @surname = args[:surname]
36
+ @forenames = args[:forenames]
37
+ @initials = args[:initials]
38
+ @additions = args[:additions]
39
+ @prefix = args[:prefix]
40
+ @completename = args[:completename]
41
+ end
42
+
43
+ # @param builder [Nokogiri::XML::Builder]
44
+ def to_xml(builder)
45
+ builder.name do
46
+ if completename
47
+ builder.completename { completename.to_xml builder }
48
+ else
49
+ builder.prefix { prefix.each { |p| p.to_xml builder } } if prefix
50
+ builder.initial { initials.each { |i| i.to_xml builder } } if initials
51
+ builder.addition { additions.each { |a| a.to_xml builder } } if additions
52
+ builder.surname { surname.to_xml builder }
53
+ builder.forename { forenames.each { |f| f.to_xml builder } } if forenames
54
+ end
55
+ end
27
56
  end
28
57
  end
29
58
 
30
59
  module PersonIdentifierType
31
- ISNI = 'isni'.freeze
32
- URI = 'uri'.freeze
60
+ ISNI = 'isni'
61
+ URI = 'uri'
33
62
  end
34
63
 
35
64
  # Person identifier.
@@ -57,10 +86,20 @@ module IsoBibItem
57
86
  # @return [Array<IsoBibItem::PersonIdentifier>]
58
87
  attr_accessor :identifiers
59
88
 
60
- def initialize
61
- super
62
- @affilation = []
89
+ # @param name [IsoBibItem::FullName]
90
+ # @param affilation [Array<IsoBibItem::Affilation>]
91
+ def initialize(name:, affilation: [], contacts:)
92
+ super(contacts: contacts)
93
+ @name = name
94
+ @affilation = affilation
63
95
  @identifiers = []
64
96
  end
97
+
98
+ def to_xml(builder)
99
+ builder.person do
100
+ name.to_xml builder
101
+ affilation.each { |a| a.to_xml builder }
102
+ end
103
+ end
65
104
  end
66
105
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: false
2
2
 
3
3
  module IsoBibItem
4
- VERSION = '0.1.6'.freeze
4
+ VERSION = '0.1.7'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iso-bib-item
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-18 00:00:00.000000000 Z
11
+ date: 2018-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -177,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
177
  version: '0'
178
178
  requirements: []
179
179
  rubyforge_project:
180
- rubygems_version: 2.7.6
180
+ rubygems_version: 2.6.12
181
181
  signing_key:
182
182
  specification_version: 4
183
183
  summary: 'IsoBibItem: Ruby ISOXMLDOC impementation.'