relaton-iso-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 +5 -5
- data/Gemfile.lock +2 -2
- data/README.adoc +16 -0
- data/lib/relaton_iso_bib/hash_converter.rb +91 -0
- data/lib/relaton_iso_bib/iso_bibliographic_item.rb +2 -1
- data/lib/relaton_iso_bib/version.rb +1 -1
- data/lib/relaton_iso_bib/xml_parser.rb +0 -3
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b7186f4c94d9264e4c612ee7f6b78d89186de54e
|
4
|
+
data.tar.gz: 883a9686aeb8bc30b808643c9f20ad142f5d2695
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a495890926f73ab84695d8731808090e15b9b0f78e9ebea55b5ab5128cb1e6e8f4cf14a1f2450007454dbd9ba617203082f71b041c69a6df7da1de9a76fffbd7
|
7
|
+
data.tar.gz: f6f2ede12ef37216211f7d653295909e0b59af1485a23c4710f3f9a7aced71352c0c4043daaafb43241dd4ad2bd0e846a4213baba1c7a6abee4aecae0e41fc5c
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
relaton-iso-bib (0.3.
|
4
|
+
relaton-iso-bib (0.3.2)
|
5
5
|
isoics (~> 0.1.6)
|
6
6
|
relaton-bib (~> 0.3.0)
|
7
7
|
ruby_deep_clone (~> 0.8.0)
|
@@ -34,7 +34,7 @@ GEM
|
|
34
34
|
pry (~> 0.10)
|
35
35
|
public_suffix (3.1.1)
|
36
36
|
rake (10.5.0)
|
37
|
-
relaton-bib (0.3.
|
37
|
+
relaton-bib (0.3.2)
|
38
38
|
addressable
|
39
39
|
nokogiri (~> 1.10)
|
40
40
|
rspec (3.8.0)
|
data/README.adoc
CHANGED
@@ -511,6 +511,22 @@ item.to_xml(bibdata: true, note: [{ type: "note type", text: "test note" }])
|
|
511
511
|
...
|
512
512
|
----
|
513
513
|
|
514
|
+
=== Create bibliographic item form YAML
|
515
|
+
[source,ruby]
|
516
|
+
----
|
517
|
+
hash = YAML.load_file 'spec/examples/iso_bib_item.yml'
|
518
|
+
=> {"id"=>"ISO/TC211",
|
519
|
+
...
|
520
|
+
|
521
|
+
bib_hash = RelatonIsoBib::HashConverter.hash_to_bib hash
|
522
|
+
=> {:id=>"ISO/TC211",
|
523
|
+
...
|
524
|
+
|
525
|
+
RelatonIsoBib::IsoBibliographicItem.new bib_hash
|
526
|
+
=> #<RelatonIsoBib::IsoBibliographicItem:0x007fdb95ba98e8
|
527
|
+
...
|
528
|
+
----
|
529
|
+
|
514
530
|
== BibliographicItem
|
515
531
|
|
516
532
|
The ISO standards use a subset of the generic bibliographic fields specified in the https://github.com/metanorma/metanorma-model-iso#iso-bibliographic-item[IsoBibliographicItem model]:
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module RelatonIsoBib
|
2
|
+
class HashConverter < RelatonBib::HashConverter
|
3
|
+
class << self
|
4
|
+
# @override RelatonBib::HashConverter.hash_to_bib
|
5
|
+
# @param args [Hash]
|
6
|
+
# @param nested [TrueClass, FalseClass]
|
7
|
+
# @return [Hash]
|
8
|
+
def hash_to_bib(args, nested = false)
|
9
|
+
ret = super
|
10
|
+
return if ret.nil?
|
11
|
+
|
12
|
+
editorialgroup_hash_to_bib(ret)
|
13
|
+
ics_hash_to_bib(ret)
|
14
|
+
structuredidentifier_hash_to_bib(ret)
|
15
|
+
ret
|
16
|
+
end
|
17
|
+
|
18
|
+
def split_title(content, lang = "en", script = "Latn")
|
19
|
+
titles = content&.split " -- "
|
20
|
+
case titles&.size
|
21
|
+
when nil, 0
|
22
|
+
intro, main, part = nil, "", nil
|
23
|
+
when 1
|
24
|
+
intro, main, part = nil, titles[0], nil
|
25
|
+
when 2
|
26
|
+
if /^(Part|Partie) \d+:/ =~ titles[1]
|
27
|
+
intro, main, part = nil, titles[0], titles[1]
|
28
|
+
else
|
29
|
+
intro, main, part = titles[0], titles[1], nil
|
30
|
+
end
|
31
|
+
when 3
|
32
|
+
intro, main, part = titles[0], titles[1], titles[2]
|
33
|
+
else
|
34
|
+
intro, main, part = titles[0], titles[1], titles[2..-1]&.join(" -- ")
|
35
|
+
end
|
36
|
+
{
|
37
|
+
title_intro: intro,
|
38
|
+
title_main: main,
|
39
|
+
title_part: part,
|
40
|
+
language: lang,
|
41
|
+
script: script,
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def title_hash_to_bib(ret)
|
48
|
+
return unless ret[:title]
|
49
|
+
|
50
|
+
ret[:title] = array(ret[:title])
|
51
|
+
ret[:title] = ret[:title].map do |t|
|
52
|
+
titleparts = {}
|
53
|
+
titleparts = split_title(t) unless t.is_a?(Hash)
|
54
|
+
if t.is_a?(Hash) && t[:content]
|
55
|
+
titleparts = split_title(t[:content], t[:language], t[:script])
|
56
|
+
end
|
57
|
+
if t.is_a?(Hash) then t.merge(titleparts)
|
58
|
+
else
|
59
|
+
{ content: t, language: "en", script: "Latn", format: "text/plain", type: "main" }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def editorialgroup_hash_to_bib(ret)
|
65
|
+
eg = ret[:editorialgroup]
|
66
|
+
return unless eg
|
67
|
+
|
68
|
+
ret[:editorialgroup] = EditorialGroup.new(
|
69
|
+
technical_committee: eg[:technical_committee],
|
70
|
+
subcommittee: eg[:subcommittee],
|
71
|
+
workgroup: eg[:workgroup],
|
72
|
+
secretariat: eg[:secretariat],
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
def ics_hash_to_bib(ret)
|
77
|
+
ret[:ics] = ret.fetch(:ics, []).map do |ics|
|
78
|
+
ics[:code] ? Ics.new(ics[:code]) : Ics.new(ics)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def structuredidentifier_hash_to_bib(ret)
|
83
|
+
return unless ret[:structuredidentifier]
|
84
|
+
|
85
|
+
ret[:structuredidentifier] = RelatonIsoBib::StructuredIdentifier.new(
|
86
|
+
ret[:structuredidentifier],
|
87
|
+
)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -9,6 +9,7 @@ require "relaton_iso_bib/editorial_group"
|
|
9
9
|
require "relaton_iso_bib/xml_parser"
|
10
10
|
require "relaton_iso_bib/structured_identifier"
|
11
11
|
require "relaton_iso_bib/ics"
|
12
|
+
require "relaton_iso_bib/hash_converter"
|
12
13
|
|
13
14
|
# Add filter method to Array.
|
14
15
|
class Array
|
@@ -72,7 +73,7 @@ module RelatonIsoBib
|
|
72
73
|
# @option title [String] :language
|
73
74
|
# @option title [String] :script
|
74
75
|
#
|
75
|
-
# @param editorialgroup [Hash, RelatonIsoBib::EditorialGroup]
|
76
|
+
# @param editorialgroup [Hash, RelatonIsoBib::EditorialGroup, RelatonItu::EditorialGroup]
|
76
77
|
# @option workgrpup [String] :name
|
77
78
|
# @option workgrpup [String] :abbreviation
|
78
79
|
# @option workgrpup [String] :url
|
@@ -29,8 +29,6 @@ module RelatonIsoBib
|
|
29
29
|
data
|
30
30
|
end
|
31
31
|
|
32
|
-
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
33
|
-
|
34
32
|
# @param ext [Nokogiri::XML::Element]
|
35
33
|
# @return [RelatonIsoBib::StructuredIdentifier]
|
36
34
|
def fetch_structuredidentifier(ext)
|
@@ -44,7 +42,6 @@ module RelatonIsoBib
|
|
44
42
|
subpart: pn[:subpart], tc_document_number: tdn&.text
|
45
43
|
)
|
46
44
|
end
|
47
|
-
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
48
45
|
|
49
46
|
# Override RelatonBib::XMLParser.ttitle method.
|
50
47
|
# @param title [Nokogiri::XML::Element]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relaton-iso-bib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
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-
|
11
|
+
date: 2019-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -185,6 +185,7 @@ files:
|
|
185
185
|
- bin/setup
|
186
186
|
- lib/relaton_iso_bib.rb
|
187
187
|
- lib/relaton_iso_bib/editorial_group.rb
|
188
|
+
- lib/relaton_iso_bib/hash_converter.rb
|
188
189
|
- lib/relaton_iso_bib/ics.rb
|
189
190
|
- lib/relaton_iso_bib/iso_bibliographic_item.rb
|
190
191
|
- lib/relaton_iso_bib/iso_document_relation.rb
|
@@ -213,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
213
214
|
version: '0'
|
214
215
|
requirements: []
|
215
216
|
rubyforge_project:
|
216
|
-
rubygems_version: 2.
|
217
|
+
rubygems_version: 2.6.12
|
217
218
|
signing_key:
|
218
219
|
specification_version: 4
|
219
220
|
summary: 'RelatonIsoBib: Ruby ISOXMLDOC impementation.'
|