relaton-bib 0.3.1 → 0.3.2

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: 6f04fbf9d97bcbdf157f86fcaa56df0898826220df4458dfe19021f45fbf2f49
4
- data.tar.gz: 3f9430241262b2ce35db7bba082f3ff0657b4ac5144deb6a2885a507013176c0
2
+ SHA1:
3
+ metadata.gz: 4e9e77fcafd4d9937bc4076463c4b96cf7fffada
4
+ data.tar.gz: 5eff627669c4a456d41b15f85f898bfc3563310f
5
5
  SHA512:
6
- metadata.gz: b8b3cae293ee147603f2ac2886e29838697b96a95faa9c1ca2e1169d631e165727067f33deedf2dd457c7c01080fe86f373a0af211172ed137a81bcb49e4df03
7
- data.tar.gz: 4f0acb9683c481e7196551edc1336e1fb1d0caf2e5638447fc460e31a1fde2232f06f4374b6a0dcaf0c5cacf5adf59d07d30299d3d7d0d40705807c36716a2f9
6
+ metadata.gz: 968fa8eae4a590a4fc392a9cde9c97059e5b07e692db31fbbc74d5c00f196b301d55df226261586587bad2d009a2cba55e1e170239508fbd2ce367f930c62f81
7
+ data.tar.gz: 96cfc0b51bb02bebcfcf5583ea2aa30ef02886bac7ae04a42b43e626c167a03518ba1289c0ecd5cd4c37d2cd1e359bdabf167d643299d101ca2eed774dcfe947
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- relaton-bib (0.3.0)
4
+ relaton-bib (0.3.2)
5
5
  addressable
6
6
  nokogiri (~> 1.10)
7
7
 
data/README.adoc CHANGED
@@ -308,6 +308,21 @@ item.to_xml date_format: :full
308
308
  </date>
309
309
  ...
310
310
  ----
311
+ === Create bibliographic item form YAML
312
+ [source,ruby]
313
+ ----
314
+ hash = YAML.load_file 'spec/examples/bib_item.yml'
315
+ => {"id"=>"ISO/TC211",
316
+ ...
317
+
318
+ bib_hash = RelatonBib::HashConverter.hash_to_bib hash
319
+ => {:id=>"ISO/TC211",
320
+ ...
321
+
322
+ RelatonBib::BibliographicItem.new bib_hash
323
+ => #<RelatonBib::BibliographicItem:0x007ff1524f8c88
324
+ ...
325
+ ----
311
326
 
312
327
  == Development
313
328
 
data/docs/hash.adoc CHANGED
@@ -9,10 +9,10 @@ the following are equivalent:
9
9
 
10
10
  [source,yaml]
11
11
  ....
12
- titles:
12
+ title:
13
13
  - type: main
14
14
  content: Geographic information
15
- titles:
15
+ title:
16
16
  type: main
17
17
  content: Geographic information
18
18
  script:
@@ -32,7 +32,7 @@ id: ISO/TC211
32
32
  # date record was created
33
33
  fetched: 2019-06-30
34
34
  # titles are an array, with a mandatory type and content, and optional format, language and script
35
- titles:
35
+ title:
36
36
  - type: main
37
37
  content: Geographic information
38
38
  - type: subtitle
@@ -73,7 +73,7 @@ docstatus:
73
73
  substage: substage
74
74
  iteration: iteration
75
75
  # date is an array, with mandatory type, and either an "on" value or a "from" and optional "to" value
76
- dates:
76
+ date:
77
77
  - type: issued
78
78
  value: 2014
79
79
  - type: published
@@ -105,7 +105,7 @@ abstract:
105
105
  # are phones, emails, uris; they contain a type giving the field name, and a value.
106
106
  # Affiliations are an array, and they contains an organization, and an optional description.
107
107
  # The affiliation description can be a single string, or a hash of content, language, script, and format.
108
- contributors:
108
+ contributor:
109
109
  - organization:
110
110
  name: International Organization for Standardization
111
111
  url: www.iso.org
@@ -124,11 +124,11 @@ contributors:
124
124
  - organization:
125
125
  name: IETF
126
126
  abbreviation: IETF
127
- identifiers:
127
+ identifier:
128
128
  - type: uri
129
129
  id: www.ietf.org
130
130
  description: Affiliation description
131
- contacts:
131
+ contact:
132
132
  - street:
133
133
  - 8 Street St
134
134
  city: City
@@ -141,7 +141,7 @@ contributors:
141
141
  - person:
142
142
  name: IETF
143
143
  abbreviation: IETF
144
- identifiers:
144
+ identifier:
145
145
  - type: uri
146
146
  id: www.ietf.org
147
147
  role:
@@ -149,7 +149,7 @@ contributors:
149
149
  - person:
150
150
  name:
151
151
  language: en
152
- initials:
152
+ initial:
153
153
  - A.
154
154
  surname: Bierman
155
155
  affiliation:
@@ -160,10 +160,10 @@ contributors:
160
160
  content: Affiliation description
161
161
  language: en
162
162
  script: Latn
163
- identifiers:
163
+ identifier:
164
164
  - type: uri
165
165
  id: www.person.com
166
- roles:
166
+ role:
167
167
  author
168
168
  # copyright consists of an owner (a hash containing the fields of an organisation),
169
169
  # a "from" date, and an optional "to" date
@@ -185,7 +185,7 @@ link:
185
185
  # relations are an array of type, bibitem, and bib_locality.
186
186
  # bibitem contains any of the attributes of a bibliographic item.
187
187
  # bib_locality is an array that contains a type, a reference_from, and optionally a reference_to
188
- relations:
188
+ relation:
189
189
  - type: updates
190
190
  bibitem:
191
191
  formattedref: ISO 19115:2003
@@ -311,8 +311,8 @@ docid::
311
311
  type::: ISO
312
312
  id::: ISO 123
313
313
  type:: standard
314
- contributors::
315
- roles::: author
314
+ contributor::
315
+ role::: author
316
316
  person:::
317
317
  name::::
318
318
  +
@@ -374,14 +374,14 @@ docstatus::
374
374
  stage::: stage
375
375
  substage::: substage
376
376
  iteration::: iteration
377
- dates::
377
+ date::
378
378
  type::: issued
379
379
  value::: 2014
380
- dates::
380
+ date::
381
381
  type::: published
382
382
  from::: 2014-04
383
383
  to::: 2014-05
384
- dates::
384
+ date::
385
385
  type::: accessed
386
386
  value::: 2015-05-20
387
387
  abstract::
@@ -451,21 +451,21 @@ person::
451
451
  organization::::
452
452
  name::::: IETF
453
453
  abbreviation::::: IETF
454
- identifiers:::::
454
+ identifier:::::
455
455
  +
456
456
  ---
457
457
  type:: uri
458
458
  id:: www.ietf.org
459
459
  ---
460
460
  description:::: Affiliation description
461
- contacts:::
461
+ contact:::
462
462
  street::::
463
463
  * 8 Street St
464
464
  city:::: City
465
465
  postcode:::: 123456
466
466
  country:::: Country
467
467
  state:::: State
468
- contacts:::
468
+ contact:::
469
469
  type:::: phone
470
470
  value:::: 223322
471
471
  role:: author
@@ -474,7 +474,7 @@ role:: author
474
474
  person::
475
475
  name::: IETF
476
476
  abbreviation::: IETF
477
- identifiers:::
477
+ identifier:::
478
478
  type:::: uri
479
479
  id:::: www.ietf.org
480
480
  role:: publisher
@@ -483,7 +483,7 @@ role:: publisher
483
483
  person::
484
484
  name:::
485
485
  language:::: en
486
- initials:::: A.
486
+ initial:::: A.
487
487
  surname:::: Bierman
488
488
  affiliation:::
489
489
  organization::::
@@ -493,10 +493,10 @@ person::
493
493
  content::::: Affiliation description
494
494
  language::::: en
495
495
  script::::: Latn
496
- identifiers:::
496
+ identifier:::
497
497
  type:::: uri
498
498
  id:::: www.person.com
499
- roles:: author
499
+ role:: author
500
500
 
501
501
  ==== Relation
502
502
  type:: updates
@@ -1,17 +1,4 @@
1
1
  module RelatonBib
2
- class << self
3
- def biblionote_hash_to_bib(ret)
4
- return unless ret[:biblionote]
5
- ret[:biblionote] = array(ret[:biblionote])
6
- (ret[:biblionote])&.each_with_index do |n, i|
7
- ret[:biblionote][i] =
8
- BiblioNote.new(content: n[:content], type: n[:type],
9
- language: n[:language],
10
- script: n[:script], format: n[:format])
11
- end
12
- end
13
- end
14
-
15
2
  class BiblioNote < FormattedString
16
3
  # @return [String]
17
4
  attr_reader :type
@@ -1,14 +1,5 @@
1
1
  module RelatonBib
2
2
  # Version
3
- class << self
4
- def version_hash_to_bib(ret)
5
- return unless ret[:version]
6
- ret[:version][:draft] = array(ret[:version][:draft])
7
- ret[:version] and ret[:version] = BibliographicItem::Version.new(
8
- ret[:version][:revision_date], ret[:version][:draft])
9
- end
10
- end
11
-
12
3
  class BibliographicItem
13
4
  class Version
14
5
  # @return [String]
@@ -3,20 +3,6 @@
3
3
  require "time"
4
4
 
5
5
  module RelatonBib
6
- class << self
7
- def dates_hash_to_bib(ret)
8
- return unless ret[:date]
9
- ret[:date] = array(ret[:date])
10
- ret[:date].each_with_index do |d, i|
11
- # value is synonym of on: it is reserved word in YAML
12
- if d[:value]
13
- ret[:date][i][:on] ||= d[:value]
14
- ret[:date][i].delete(:value)
15
- end
16
- end
17
- end
18
- end
19
-
20
6
  # Bibliographic date.
21
7
  class BibliographicDate
22
8
  TYPES = %w[published accessed created implemented obsoleted confirmed
@@ -21,59 +21,9 @@ require "relaton_bib/xml_parser"
21
21
  require "relaton_bib/biblio_note"
22
22
  require "relaton_bib/biblio_version"
23
23
  require "relaton_bib/workers_pool"
24
- require "relaton_bib/hash_to_bib.rb"
24
+ require "relaton_bib/hash_converter"
25
25
 
26
26
  module RelatonBib
27
- class << self
28
- def extent_hash_to_bib(ret)
29
- return unless ret[:extent]
30
- ret[:extent] = array(ret[:extent])
31
- ret[:extent]&.each_with_index do |e, i|
32
- ret[:extent][i] = BibItemLocality.new(e[:type], e[:reference_from],
33
- e[:reference_to])
34
- end
35
- end
36
-
37
- def title_hash_to_bib(ret)
38
- return unless ret[:title]
39
- ret[:title] = array(ret[:title])
40
- ret[:title] = ret[:title].map do |t|
41
- t.is_a?(Hash) ? t : { content: t, language: "en", script: "Latn",
42
- format: "text/plain", type: "main" }
43
- end
44
- end
45
-
46
- def language_hash_to_bib(ret)
47
- return unless ret[:language]
48
- ret[:language] = array(ret[:language])
49
- end
50
-
51
- def script_hash_to_bib(ret)
52
- return unless ret[:script]
53
- ret[:script] = array(ret[:script])
54
- end
55
-
56
- def abstract_hash_to_bib(ret)
57
- return unless ret[:abstract]
58
- ret[:abstract] = array(ret[:abstract])
59
- end
60
-
61
- def link_hash_to_bib(ret)
62
- return unless ret[:link]
63
- ret[:link] = array(ret[:link])
64
- end
65
-
66
- def place_hash_to_bib(ret)
67
- return unless ret[:place]
68
- ret[:place] = array(ret[:place])
69
- end
70
-
71
- def accesslocation_hash_to_bib(ret)
72
- return unless ret[:accesslocation]
73
- ret[:accesslocation] = array(ret[:accesslocation])
74
- end
75
- end
76
-
77
27
  # Bibliographic item
78
28
  class BibliographicItem
79
29
  TYPES = %W[article book booklet conference manual proceedings presentation
@@ -1,15 +1,4 @@
1
1
  module RelatonBib
2
- class << self
3
- def classification_hash_to_bib(ret)
4
- #ret[:classification] = [ret[:classification]] unless ret[:classification].is_a?(Array)
5
- #ret[:classification]&.each_with_index do |c, i|
6
- #ret[:classification][i] = RelatonBib::Classification.new(c)
7
- #end
8
- ret[:classification] and
9
- ret[:classification] = Classification.new(ret[:classification])
10
- end
11
- end
12
-
13
2
  class Classification
14
3
  # @return [String, NilClass]
15
4
  attr_reader :type
@@ -4,19 +4,6 @@ require "relaton_bib/person"
4
4
 
5
5
  # RelatonBib module
6
6
  module RelatonBib
7
- class << self
8
- def contributors_hash_to_bib(ret)
9
- return unless ret[:contributor]
10
- ret[:contributor] = array(ret[:contributor])
11
- ret[:contributor]&.each_with_index do |c, i|
12
- ret[:contributor][i][:role] = array(ret[:contributor][i][:role])
13
- ret[:contributor][i][:entity] = c[:person] ?
14
- person_hash_to_bib(c[:person]) : org_hash_to_bib(c[:organization])
15
- ret[:contributor][i].delete(:person)
16
- ret[:contributor][i].delete(:organization)
17
- end
18
- end
19
- end
20
7
 
21
8
  # Contributor's role.
22
9
  class ContributorRole
@@ -33,13 +20,13 @@ module RelatonBib
33
20
  # @param type [String] allowed types "author", "editor",
34
21
  # "cartographer", "publisher"
35
22
  # @param description [Array<String>]
36
- def initialize(*args)
37
- @type = args.fetch 0
38
- if type && !TYPES.include?(type)
23
+ def initialize(**args)
24
+ if args[:type] && !TYPES.include?(args[:type])
39
25
  raise ArgumentError, %{Type "#{type}" is invalid.}
40
26
  end
41
27
 
42
- @description = args.fetch(1, []).map { |d| FormattedString.new content: d, format: nil }
28
+ @type = args[:type]
29
+ @description = args.fetch(:description, []).map { |d| FormattedString.new content: d, format: nil }
43
30
  end
44
31
 
45
32
  def to_xml(builder)
@@ -62,9 +49,9 @@ module RelatonBib
62
49
 
63
50
  # @param entity [RelatonBib::Person, RelatonBib::Organization]
64
51
  # @param role [Array<String>]
65
- def initialize(entity:, role: ["publisher"])
52
+ def initialize(entity:, role: [{ type: "publisher" }])
66
53
  @entity = entity
67
- @role = role.map { |r| ContributorRole.new(*r) }
54
+ @role = role.map { |r| ContributorRole.new(**r) }
68
55
  end
69
56
 
70
57
  def to_xml(builder)
@@ -3,34 +3,6 @@
3
3
  require "uri"
4
4
 
5
5
  module RelatonBib
6
- class << self
7
- def affiliation_hash_to_bib(c)
8
- return [] unless c[:affiliation]
9
- array(c[:affiliation]).map do |a|
10
- a[:description] = array(a[:description])&.map do |d|
11
- FormattedString.new(
12
- d.is_a?(Hash) ?
13
- { content: d[:content], language: d[:language],
14
- script: d[:script], format: d[:format] } :
15
- { content: d })
16
- end
17
- Affilation.new(
18
- Organization.new(org_hash_to_bib(a[:organization])), a[:description])
19
- end
20
- end
21
-
22
- def contacts_hash_to_bib(c)
23
- return [] unless c[:contact]
24
- array(c[:contact]).map do |a|
25
- (a[:city] || a[:country]) ?
26
- RelatonBib::Address.new(
27
- street: Array(a[:street]), city: a[:city], postcode: a[:postcode],
28
- country: a[:country], state: a[:state]) :
29
- RelatonBib::Contact.new(type: a[:type], value: a[:value])
30
- end
31
- end
32
- end
33
-
34
6
  # Address class.
35
7
  class Address
36
8
  # @return [Array<String>]
@@ -1,16 +1,5 @@
1
1
  module RelatonBib
2
2
  # Document identifier.
3
-
4
- class << self
5
- def docid_hash_to_bib(ret)
6
- return unless ret[:docid]
7
- ret[:docid] = array(ret[:docid])
8
- ret[:docid]&.each_with_index do |id, i|
9
- ret[:docid][i] = DocumentIdentifier.new(id: id[:id], type: id[:type])
10
- end
11
- end
12
- end
13
-
14
3
  class DocumentIdentifier
15
4
  # @return [String]
16
5
  attr_reader :id
@@ -11,33 +11,6 @@ module RelatonBib
11
11
  # IDENTICAL = 'identical'
12
12
  # NONEQUIVALENT = 'nonequivalent'
13
13
  # end
14
- class << self
15
- def relations_hash_to_bib(ret)
16
- return unless ret[:relation]
17
- ret[:relation] = array(ret[:relation])
18
- ret[:relation]&.each_with_index do |r, i|
19
- relation_bibitem_hash_to_bib(ret, r, i)
20
- relation_biblocality_hash_to_bib(ret, r, i)
21
- end
22
- end
23
-
24
- def relation_bibitem_hash_to_bib(ret, r, i)
25
- if r[:bibitem] then ret[:relation][i][:bibitem] =
26
- BibliographicItem.new(hash_to_bib(r[:bibitem], true))
27
- else
28
- warn "bibitem missing: #{r}"
29
- ret[:relation][i][:bibitem] = nil
30
- end
31
- end
32
-
33
- def relation_biblocality_hash_to_bib(ret, r, i)
34
- ret[:relation][i][:bib_locality] =
35
- array(r[:bib_locality])&.map do |bl|
36
- BibItemLocality.new(bl[:type], bl[:reference_from],
37
- bl[:reference_to])
38
- end
39
- end
40
- end
41
14
 
42
15
  # Documett relation
43
16
  class DocumentRelation
@@ -3,15 +3,6 @@
3
3
  require "relaton_bib/localized_string"
4
4
 
5
5
  module RelatonBib
6
- class << self
7
- def docstatus_hash_to_bib(ret)
8
- ret[:docstatus] and ret[:docstatus] =
9
- DocumentStatus.new(stage: ret[:docstatus][:stage],
10
- substage: ret[:docstatus][:substage],
11
- iteration: ret[:docstatus][:iteration])
12
- end
13
- end
14
-
15
6
  # Document status.
16
7
  class DocumentStatus
17
8
  # @return [String]
@@ -1,13 +1,6 @@
1
1
  require "relaton_bib/formatted_string"
2
2
 
3
3
  module RelatonBib
4
- class << self
5
- def formattedref_hash_to_bib(ret)
6
- ret[:formattedref] and ret[:formattedref] =
7
- formattedref(ret[:formattedref])
8
- end
9
- end
10
-
11
4
  class FormattedRef < FormattedString
12
5
  # @param [Nokogiri::XML::Builder]
13
6
  def to_xml(builder)
@@ -0,0 +1,311 @@
1
+ module RelatonBib
2
+ class HashConverter
3
+ class << self
4
+ def hash_to_bib(args, nested = false)
5
+ return nil unless args.is_a?(Hash)
6
+
7
+ ret = Marshal.load(Marshal.dump(symbolize(args))) # deep copy
8
+ timestamp_hash(ret) unless nested
9
+ title_hash_to_bib(ret)
10
+ link_hash_to_bib(ret)
11
+ language_hash_to_bib(ret)
12
+ script_hash_to_bib(ret)
13
+ dates_hash_to_bib(ret)
14
+ docid_hash_to_bib(ret)
15
+ version_hash_to_bib(ret)
16
+ biblionote_hash_to_bib(ret)
17
+ abstract_hash_to_bib(ret)
18
+ formattedref_hash_to_bib(ret)
19
+ docstatus_hash_to_bib(ret)
20
+ contributors_hash_to_bib(ret)
21
+ relations_hash_to_bib(ret)
22
+ series_hash_to_bib(ret)
23
+ medium_hash_to_bib(ret)
24
+ place_hash_to_bib(ret)
25
+ extent_hash_to_bib(ret)
26
+ accesslocation_hash_to_bib(ret)
27
+ classification_hash_to_bib(ret)
28
+ validity_hash_to_bib(ret)
29
+ ret
30
+ end
31
+
32
+ def timestamp_hash(ret)
33
+ ret[:fetched] ||= Date.today.to_s
34
+ end
35
+
36
+ def extent_hash_to_bib(ret)
37
+ return unless ret[:extent]
38
+ ret[:extent] = array(ret[:extent])
39
+ ret[:extent]&.each_with_index do |e, i|
40
+ ret[:extent][i] = BibItemLocality.new(e[:type], e[:reference_from],
41
+ e[:reference_to])
42
+ end
43
+ end
44
+
45
+ def title_hash_to_bib(ret)
46
+ return unless ret[:title]
47
+ ret[:title] = array(ret[:title])
48
+ ret[:title] = ret[:title].map do |t|
49
+ t.is_a?(Hash) ? t : { content: t, language: "en", script: "Latn",
50
+ format: "text/plain", type: "main" }
51
+ end
52
+ end
53
+
54
+ def language_hash_to_bib(ret)
55
+ return unless ret[:language]
56
+ ret[:language] = array(ret[:language])
57
+ end
58
+
59
+ def script_hash_to_bib(ret)
60
+ return unless ret[:script]
61
+ ret[:script] = array(ret[:script])
62
+ end
63
+
64
+ def abstract_hash_to_bib(ret)
65
+ return unless ret[:abstract]
66
+ ret[:abstract] = array(ret[:abstract])
67
+ end
68
+
69
+ def link_hash_to_bib(ret)
70
+ return unless ret[:link]
71
+ ret[:link] = array(ret[:link])
72
+ end
73
+
74
+ def place_hash_to_bib(ret)
75
+ return unless ret[:place]
76
+ ret[:place] = array(ret[:place])
77
+ end
78
+
79
+ def accesslocation_hash_to_bib(ret)
80
+ return unless ret[:accesslocation]
81
+ ret[:accesslocation] = array(ret[:accesslocation])
82
+ end
83
+
84
+ def dates_hash_to_bib(ret)
85
+ return unless ret[:date]
86
+ ret[:date] = array(ret[:date])
87
+ ret[:date].each_with_index do |d, i|
88
+ # value is synonym of on: it is reserved word in YAML
89
+ if d[:value]
90
+ ret[:date][i][:on] ||= d[:value]
91
+ ret[:date][i].delete(:value)
92
+ end
93
+ end
94
+ end
95
+
96
+ def docid_hash_to_bib(ret)
97
+ return unless ret[:docid]
98
+ ret[:docid] = array(ret[:docid])
99
+ ret[:docid]&.each_with_index do |id, i|
100
+ ret[:docid][i] = DocumentIdentifier.new(id: id[:id], type: id[:type])
101
+ end
102
+ end
103
+
104
+ def version_hash_to_bib(ret)
105
+ return unless ret[:version]
106
+ ret[:version][:draft] = array(ret[:version][:draft])
107
+ ret[:version] and ret[:version] = BibliographicItem::Version.new(
108
+ ret[:version][:revision_date], ret[:version][:draft])
109
+ end
110
+
111
+ def biblionote_hash_to_bib(ret)
112
+ return unless ret[:biblionote]
113
+ ret[:biblionote] = array(ret[:biblionote])
114
+ (ret[:biblionote])&.each_with_index do |n, i|
115
+ ret[:biblionote][i] =
116
+ BiblioNote.new(content: n[:content], type: n[:type],
117
+ language: n[:language],
118
+ script: n[:script], format: n[:format])
119
+ end
120
+ end
121
+
122
+ def formattedref_hash_to_bib(ret)
123
+ ret[:formattedref] and ret[:formattedref] =
124
+ formattedref(ret[:formattedref])
125
+ end
126
+
127
+ def docstatus_hash_to_bib(ret)
128
+ ret[:docstatus] and ret[:docstatus] =
129
+ DocumentStatus.new(stage: ret[:docstatus][:stage],
130
+ substage: ret[:docstatus][:substage],
131
+ iteration: ret[:docstatus][:iteration])
132
+ end
133
+
134
+ def contributors_hash_to_bib(ret)
135
+ return unless ret[:contributor]
136
+ ret[:contributor] = array(ret[:contributor])
137
+ ret[:contributor]&.each_with_index do |c, i|
138
+ roles = array(ret[:contributor][i][:role]).map do |r|
139
+ if r.is_a? Array
140
+ { type: r[0], description: r.fetch(1) }
141
+ else
142
+ { type: r }
143
+ end
144
+ end
145
+ ret[:contributor][i][:role] = roles
146
+ ret[:contributor][i][:entity] = c[:person] ?
147
+ person_hash_to_bib(c[:person]) : org_hash_to_bib(c[:organization])
148
+ ret[:contributor][i].delete(:person)
149
+ ret[:contributor][i].delete(:organization)
150
+ end
151
+ end
152
+
153
+ def org_hash_to_bib(c)
154
+ return nil if c.nil?
155
+ c[:identifier] = array(c[:identifier])&.map do |a|
156
+ OrgIdentifier.new(a[:type], a[:id])
157
+ end
158
+ c
159
+ end
160
+
161
+ def person_hash_to_bib(c)
162
+ Person.new(
163
+ name: fullname_hash_to_bib(c),
164
+ affiliation: affiliation_hash_to_bib(c),
165
+ contact: contacts_hash_to_bib(c),
166
+ identifier: person_identifiers_hash_to_bib(c),
167
+ )
168
+ end
169
+
170
+ def fullname_hash_to_bib(c)
171
+ n = c[:name]
172
+ FullName.new(
173
+ forename: array(n[:forename])&.map { |f| localname(f, c) },
174
+ initial: array(n[:initial])&.map { |f| localname(f, c) },
175
+ addition: array(n[:addition])&.map { |f| localname(f, c) },
176
+ prefix: array(n[:prefix])&.map { |f| localname(f, c) },
177
+ surname: localname(n[:surname], c),
178
+ completename: localname(n[:completename], c),
179
+ )
180
+ end
181
+
182
+ def person_identifiers_hash_to_bib(c)
183
+ array(c[:identifier])&.map do |a|
184
+ PersonIdentifier.new(a[:type], a[:id])
185
+ end
186
+ end
187
+
188
+ def affiliation_hash_to_bib(c)
189
+ return [] unless c[:affiliation]
190
+ array(c[:affiliation]).map do |a|
191
+ a[:description] = array(a[:description])&.map do |d|
192
+ FormattedString.new(
193
+ d.is_a?(Hash) ?
194
+ { content: d[:content], language: d[:language],
195
+ script: d[:script], format: d[:format] } :
196
+ { content: d })
197
+ end
198
+ Affilation.new(
199
+ Organization.new(org_hash_to_bib(a[:organization])), a[:description])
200
+ end
201
+ end
202
+
203
+ def contacts_hash_to_bib(c)
204
+ return [] unless c[:contact]
205
+ array(c[:contact]).map do |a|
206
+ (a[:city] || a[:country]) ?
207
+ RelatonBib::Address.new(
208
+ street: Array(a[:street]), city: a[:city], postcode: a[:postcode],
209
+ country: a[:country], state: a[:state]) :
210
+ RelatonBib::Contact.new(type: a[:type], value: a[:value])
211
+ end
212
+ end
213
+
214
+ def relations_hash_to_bib(ret)
215
+ return unless ret[:relation]
216
+ ret[:relation] = array(ret[:relation])
217
+ ret[:relation]&.each_with_index do |r, i|
218
+ relation_bibitem_hash_to_bib(ret, r, i)
219
+ relation_biblocality_hash_to_bib(ret, r, i)
220
+ end
221
+ end
222
+
223
+ def relation_bibitem_hash_to_bib(ret, r, i)
224
+ if r[:bibitem] then ret[:relation][i][:bibitem] =
225
+ BibliographicItem.new(hash_to_bib(r[:bibitem], true))
226
+ else
227
+ warn "bibitem missing: #{r}"
228
+ ret[:relation][i][:bibitem] = nil
229
+ end
230
+ end
231
+
232
+ def relation_biblocality_hash_to_bib(ret, r, i)
233
+ ret[:relation][i][:bib_locality] =
234
+ array(r[:bib_locality])&.map do |bl|
235
+ BibItemLocality.new(bl[:type], bl[:reference_from],
236
+ bl[:reference_to])
237
+ end
238
+ end
239
+
240
+ def series_hash_to_bib(ret)
241
+ array(ret[:series])&.each_with_index do |s, i|
242
+ s[:formattedref] and s[:formattedref] = formattedref(s[:formattedref])
243
+ if s[:title]
244
+ s[:title] = { content: s[:title] } unless s.is_a?(Hash)
245
+ s[:title] = TypedTitleString.new(s[:title])
246
+ end
247
+ s[:abbreviation] and
248
+ s[:abbreviation] = localizedstring(s[:abbreviation])
249
+ ret[:series][i] = Series.new(s)
250
+ end
251
+ end
252
+
253
+ def medium_hash_to_bib(ret)
254
+ ret[:medium] and ret[:medium] = Medium.new(ret[:medium])
255
+ end
256
+
257
+ def classification_hash_to_bib(ret)
258
+ #ret[:classification] = [ret[:classification]] unless ret[:classification].is_a?(Array)
259
+ #ret[:classification]&.each_with_index do |c, i|
260
+ #ret[:classification][i] = RelatonBib::Classification.new(c)
261
+ #end
262
+ ret[:classification] and
263
+ ret[:classification] = Classification.new(ret[:classification])
264
+ end
265
+
266
+ def validity_hash_to_bib(ret)
267
+ return unless ret[:validity]
268
+ ret[:validity][:begins] and b = Time.parse(ret[:validity][:begins])
269
+ ret[:validity][:ends] and e = Time.parse(ret[:validity][:ends])
270
+ ret[:validity][:revision] and r = Time.parse(ret[:validity][:revision])
271
+ ret[:validity] = Validity.new(begins: b, ends: e, revision: r)
272
+ end
273
+
274
+ def symbolize(obj)
275
+ obj.is_a? Hash and
276
+ return obj.inject({}){|memo,(k,v)| memo[k.to_sym] = symbolize(v); memo}
277
+ obj.is_a? Array and
278
+ return obj.inject([]){|memo,v | memo << symbolize(v); memo}
279
+ return obj
280
+ end
281
+
282
+ def array(a)
283
+ return [] unless a
284
+ return [a] unless a.is_a?(Array)
285
+ a
286
+ end
287
+
288
+ def localname(f, c)
289
+ return nil if f.nil?
290
+ f.is_a?(Hash) and lang = f[:language]
291
+ lang ||= c[:name][:language]
292
+ f.is_a?(Hash) and script = f[:script]
293
+ script ||= c[:name][:script]
294
+ f.is_a?(Hash) ?
295
+ RelatonBib::LocalizedString.new(f[:content], lang, script) :
296
+ RelatonBib::LocalizedString.new(f, lang, script)
297
+ end
298
+
299
+ def localizedstring(f)
300
+ f.is_a?(Hash) ?
301
+ RelatonBib::LocalizedString.new(f[:content], f[:language], f[:script]) :
302
+ RelatonBib::LocalizedString.new(f)
303
+ end
304
+
305
+ def formattedref(f)
306
+ f.is_a?(Hash) ? RelatonBib::FormattedRef.new(f) :
307
+ RelatonBib::FormattedRef.new(content: f)
308
+ end
309
+ end
310
+ end
311
+ end
@@ -1,10 +1,4 @@
1
1
  module RelatonBib
2
- class << self
3
- def medium_hash_to_bib(ret)
4
- ret[:medium] and ret[:medium] = Medium.new(ret[:medium])
5
- end
6
- end
7
-
8
2
  class Medium
9
3
  # @return [String, NilClass]
10
4
  attr_reader :form, :size, :scale
@@ -3,16 +3,6 @@
3
3
  require "relaton_bib/contributor"
4
4
 
5
5
  module RelatonBib
6
- class << self
7
- def org_hash_to_bib(c)
8
- return nil if c.nil?
9
- c[:identifier] = array(c[:identifier])&.map do |a|
10
- OrgIdentifier.new(a[:type], a[:id])
11
- end
12
- c
13
- end
14
- end
15
-
16
6
  # module OrgIdentifierType
17
7
  # ORCID = 'orcid'
18
8
  # URI = 'uri'
@@ -3,35 +3,6 @@
3
3
  require "relaton_bib/contributor"
4
4
 
5
5
  module RelatonBib
6
- class << self
7
- def person_hash_to_bib(c)
8
- Person.new(
9
- name: fullname_hash_to_bib(c),
10
- affiliation: affiliation_hash_to_bib(c),
11
- contact: contacts_hash_to_bib(c),
12
- identifier: person_identifiers_hash_to_bib(c),
13
- )
14
- end
15
-
16
- def fullname_hash_to_bib(c)
17
- n = c[:name]
18
- FullName.new(
19
- forename: array(n[:forename])&.map { |f| localname(f, c) },
20
- initial: array(n[:initial])&.map { |f| localname(f, c) },
21
- addition: array(n[:addition])&.map { |f| localname(f, c) },
22
- prefix: array(n[:prefix])&.map { |f| localname(f, c) },
23
- surname: localname(n[:surname], c),
24
- completename: localname(n[:completename], c),
25
- )
26
- end
27
-
28
- def person_identifiers_hash_to_bib(c)
29
- array(c[:identifier])&.map do |a|
30
- PersonIdentifier.new(a[:type], a[:id])
31
- end
32
- end
33
- end
34
-
35
6
  # Person's full name
36
7
  class FullName
37
8
  # @return [Array<RelatonBib::LocalizedString>]
@@ -1,21 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelatonBib
4
- class << self
5
- def series_hash_to_bib(ret)
6
- array(ret[:series])&.each_with_index do |s, i|
7
- s[:formattedref] and s[:formattedref] = formattedref(s[:formattedref])
8
- if s[:title]
9
- s[:title] = { content: s[:title] } unless s.is_a?(Hash)
10
- s[:title] = TypedTitleString.new(s[:title])
11
- end
12
- s[:abbreviation] and
13
- s[:abbreviation] = localizedstring(s[:abbreviation])
14
- ret[:series][i] = Series.new(s)
15
- end
16
- end
17
- end
18
-
19
4
  #
20
5
  # Series class.
21
6
  #
@@ -1,14 +1,4 @@
1
1
  module RelatonBib
2
- class << self
3
- def validity_hash_to_bib(ret)
4
- return unless ret[:validity]
5
- ret[:validity][:begins] and b = Time.parse(ret[:validity][:begins])
6
- ret[:validity][:ends] and e = Time.parse(ret[:validity][:ends])
7
- ret[:validity][:revision] and r = Time.parse(ret[:validity][:revision])
8
- ret[:validity] = Validity.new(begins: b, ends: e, revision: r)
9
- end
10
- end
11
-
12
2
  class Validity
13
3
  # @return [Time, NilClass]
14
4
  attr_reader :begins
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "0.3.1".freeze
2
+ VERSION = "0.3.2".freeze
3
3
  end
@@ -236,7 +236,7 @@ module RelatonBib
236
236
  elsif (person = c.at "./person") then get_person(person)
237
237
  end
238
238
  role_descr = c.xpath("./role/description").map &:text
239
- ContributionInfo.new entity: entity, role: [[c.at("role")[:type], role_descr]]
239
+ ContributionInfo.new entity: entity, role: [{ type: c.at("role")[:type], description: role_descr }]
240
240
  end
241
241
  end
242
242
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-bib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-29 00:00:00.000000000 Z
11
+ date: 2019-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -186,6 +186,7 @@ files:
186
186
  - lib/relaton_bib/document_status.rb
187
187
  - lib/relaton_bib/formatted_ref.rb
188
188
  - lib/relaton_bib/formatted_string.rb
189
+ - lib/relaton_bib/hash_converter.rb
189
190
  - lib/relaton_bib/hash_to_bib.rb
190
191
  - lib/relaton_bib/localized_string.rb
191
192
  - lib/relaton_bib/medium.rb
@@ -219,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
220
  version: '0'
220
221
  requirements: []
221
222
  rubyforge_project:
222
- rubygems_version: 2.7.6
223
+ rubygems_version: 2.6.12
223
224
  signing_key:
224
225
  specification_version: 4
225
226
  summary: 'RelatonBib: Ruby XMLDOC impementation.'