relaton-iso-bib 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,13 @@
1
+ module RelatonIsoBib
2
+ class IsoDocumentRelation < RelatonBib::DocumentRelation
3
+ # @param builder [Nokogiri::XML::Builder]
4
+ def to_xml(builder)
5
+ builder.relation(type: type) do
6
+ bibitem.to_xml(builder, {})
7
+ bib_locality.each do |l|
8
+ l.to_xml builder
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,71 @@
1
+ module RelatonIsoBib
2
+ # Document structured identifier.
3
+ class StructuredIdentifier
4
+ # @return [Integer, NilClass]
5
+ attr_reader :tc_document_number
6
+
7
+ # @return [String]
8
+ attr_reader :project_number
9
+
10
+ # @return [Integer, NilClass]
11
+ attr_reader :part
12
+
13
+ # @return [Integer, NilClass]
14
+ attr_reader :subpart
15
+
16
+ # @return [String, NilClass]
17
+ attr_reader :type
18
+
19
+ # @param tc_document_number [Integer, NilClass]
20
+ # @param project_number [String]
21
+ # @param part [String, NilClass]
22
+ # @param subpart [String, NilClass]
23
+ # @param type [String, NilClass]
24
+ def initialize(**args)
25
+ @tc_document_number = args[:tc_document_number]
26
+ @project_number = args[:project_number]
27
+ @part = args[:part]
28
+ @subpart = args[:subpart]
29
+ @prefix = args[:prefix]
30
+ @type = args[:type]
31
+ end
32
+
33
+ # in docid manipulations, assume ISO as the default: id-part:year
34
+ def remove_part
35
+ @part_number = nil
36
+ @subpart_number = nil
37
+ case @type
38
+ when "Chinese Standard" then @project_number = @project_number.sub(/\.\d+/, "")
39
+ else
40
+ @project_number = @project_number.sub(/-\d+/, "")
41
+ end
42
+ end
43
+
44
+ def remove_date
45
+ case @type
46
+ when "Chinese Standard" then @project_number = @project_number.sub(/-[12]\d\d\d/, "")
47
+ else
48
+ @project_number = @project_number.sub(/:[12]\d\d\d/, "")
49
+ end
50
+ end
51
+
52
+ def all_parts
53
+ @project_number = @project_number + " (all parts)"
54
+ end
55
+
56
+ def id
57
+ project_number
58
+ end
59
+
60
+ # @param builder [Nokogiri::XML::Builder]
61
+ def to_xml(builder)
62
+ xml = builder.structuredidentifier do
63
+ pn = builder.send "project-number", project_number
64
+ pn[:part] = part if part
65
+ pn[:subpart] = subpart if subpart
66
+ builder.send "tc-document-number", tc_document_number if tc_document_number
67
+ end
68
+ xml[:type] = type if type
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,32 @@
1
+ module RelatonIsoBib
2
+ class TypedTitleString < RelatonBib::TypedTitleString
3
+ TITLE_TYPES = %w[title-main title-intro title-part main].freeze
4
+
5
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
6
+
7
+ # @param type [String]
8
+ # @param title [RelatonBib::FormattedString, Hash]
9
+ # @param content [String]
10
+ # @param language [String]
11
+ # @param script [String]
12
+ def initialize(**args)
13
+ if args[:type] && !TITLE_TYPES.include?(args[:type])
14
+ raise ArgumentError, %{The type #{args[:type]} is invalid.}
15
+ end
16
+
17
+ unless args[:title] || args[:content]
18
+ raise ArgumentError, %{Keyword "title" or "content" should be passed.}
19
+ end
20
+
21
+ @type = args[:type]
22
+
23
+ if args[:title]
24
+ @title = args[:title]
25
+ else
26
+ fsargs = args.select { |k, _v| %i[content language script format].include? k }
27
+ @title = RelatonBib::FormattedString.new(fsargs)
28
+ end
29
+ end
30
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module RelatonIsoBib
2
+ VERSION = "0.1.0".freeze
3
+ end
@@ -0,0 +1,89 @@
1
+ require "nokogiri"
2
+
3
+ module RelatonIsoBib
4
+ class XMLParser < RelatonBib::XMLParser
5
+ class << self
6
+ # Override RelatonBib::XMLParser.form_xml method.
7
+ # @param xml [String]
8
+ # @return [RelatonIsoBib::IsoBibliographicItem]
9
+ def from_xml(xml)
10
+ doc = Nokogiri::XML(xml)
11
+ isoitem = doc.at "/bibitem|/bibdata"
12
+ IsoBibliographicItem.new item_data(isoitem)
13
+ end
14
+
15
+ private
16
+
17
+ # Override RelatonBib::XMLParser.item_data method.
18
+ # @param isoitem [Nokogiri::XML::Element]
19
+ # @returtn [Hash]
20
+ def item_data(isoitem)
21
+ data = super
22
+ ext = isoitem.at "./ext"
23
+ return data unless ext
24
+
25
+ data[:type] = ext.at("./doctype")&.text
26
+ data[:editorialgroup] = fetch_editorialgroup ext
27
+ data[:ics] = fetch_ics ext
28
+ data[:structuredidentifier] = fetch_structuredidentifier ext
29
+ data
30
+ end
31
+
32
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
33
+
34
+ # @param ext [Nokogiri::XML::Element]
35
+ # @return [RelatonIsoBib::StructuredIdentifier]
36
+ def fetch_structuredidentifier(ext)
37
+ sid = ext.at "./structuredidentifier"
38
+ pn = sid.at "project-number"
39
+ tdn = sid.at "tc-document-number"
40
+ RelatonIsoBib::StructuredIdentifier.new(
41
+ type: sid[:type], project_number: pn.text, part: pn[:part],
42
+ subpart: pn[:subpart], tc_document_number: tdn&.text
43
+ )
44
+ end
45
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
46
+
47
+ # Override RelatonBib::XMLParser.ttitle method.
48
+ # @param title [Nokogiri::XML::Element]
49
+ # @return [RelatonIsoBib::TypedTitleString]
50
+ def ttitle(title)
51
+ return unless title
52
+
53
+ TypedTitleString.new(
54
+ type: title[:type], content: title.text, language: title[:language],
55
+ script: title[:script], format: title[:format]
56
+ )
57
+ end
58
+
59
+ # @param item [Nokogiri::XML::Element]
60
+ # @return [Array<RelatonIsoBib::Ics>]
61
+ def fetch_ics(ext)
62
+ ext.xpath("./ics/code").map { |ics| Ics.new ics.text }
63
+ end
64
+
65
+ # @TODO Organization doesn't recreated
66
+ # @param ext [Nokogiri::XML::Element]
67
+ # @return [RelatonIsoBib::EditorialGroup]
68
+ def fetch_editorialgroup(ext)
69
+ eg = ext.at("./editorialgroup")
70
+ tc = eg&.xpath("technical_committee")&.map { |t| iso_subgroup(t) }
71
+ sc = eg&.xpath("subcommittee")&.map { |s| iso_subgroup(s) }
72
+ wg = eg&.xpath("workgroup")&.map { |w| iso_subgroup(w) }
73
+ sr = eg&.at "secretariat"
74
+ EditorialGroup.new(
75
+ technical_committee: tc, subcommittee: sc, workgroup: wg, secretariat: sr&.text,
76
+ )
77
+ end
78
+
79
+ # @param com [Nokogiri::XML::Element]
80
+ # @return [RelatonIsoBib::IsoSubgroup]
81
+ def iso_subgroup(com)
82
+ return nil if com.nil?
83
+
84
+ IsoSubgroup.new(name: com.text, type: com[:type],
85
+ number: com[:number].to_i)
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,7 @@
1
+ require "relaton_iso_bib/version"
2
+ require "relaton_iso_bib/iso_bibliographic_item"
3
+
4
+ module RelatonIsoBib
5
+ class Error < StandardError; end
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "relaton_iso_bib/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "relaton-iso-bib"
9
+ spec.version = RelatonIsoBib::VERSION
10
+ spec.authors = ["Ribose Inc."]
11
+ spec.email = ["open.source@ribose.com"]
12
+
13
+ spec.summary = %(RelatonIsoBib: Ruby ISOXMLDOC impementation.)
14
+ spec.description = %(RelatonIsoBib: Ruby ISOXMLDOC impementation.)
15
+ spec.homepage = "https://github.com/metanorma/relaton-iso-bib"
16
+ spec.license = "BSD-2-Clause"
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "bundler", "~> 2.0"
28
+ spec.add_development_dependency "pry-byebug"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ spec.add_development_dependency 'simplecov'
32
+ spec.add_development_dependency "equivalent-xml", "~> 0.6"
33
+ spec.add_development_dependency "ruby-debug-ide"
34
+ spec.add_development_dependency "debase"
35
+
36
+ spec.add_dependency "isoics", "~> 0.1.6"
37
+ spec.add_dependency "nokogiri", "~> 1.8.4"
38
+ spec.add_dependency "relaton-bib", "~>0.1.5"
39
+ spec.add_dependency "ruby_deep_clone", "~> 0.8.0"
40
+ end
metadata ADDED
@@ -0,0 +1,234 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: relaton-iso-bib
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ribose Inc.
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry-byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: equivalent-xml
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.6'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.6'
97
+ - !ruby/object:Gem::Dependency
98
+ name: ruby-debug-ide
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: debase
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: isoics
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.1.6
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.1.6
139
+ - !ruby/object:Gem::Dependency
140
+ name: nokogiri
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 1.8.4
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 1.8.4
153
+ - !ruby/object:Gem::Dependency
154
+ name: relaton-bib
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 0.1.5
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 0.1.5
167
+ - !ruby/object:Gem::Dependency
168
+ name: ruby_deep_clone
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: 0.8.0
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: 0.8.0
181
+ description: 'RelatonIsoBib: Ruby ISOXMLDOC impementation.'
182
+ email:
183
+ - open.source@ribose.com
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - ".gitignore"
189
+ - ".rspec"
190
+ - ".rubocop.yml"
191
+ - ".travis.yml"
192
+ - Gemfile
193
+ - Gemfile.lock
194
+ - LICENSE.txt
195
+ - README.adoc
196
+ - README.md
197
+ - Rakefile
198
+ - bin/console
199
+ - bin/setup
200
+ - lib/relaton_iso_bib.rb
201
+ - lib/relaton_iso_bib/editorial_group.rb
202
+ - lib/relaton_iso_bib/ics.rb
203
+ - lib/relaton_iso_bib/iso_bibliographic_item.rb
204
+ - lib/relaton_iso_bib/iso_document_relation.rb
205
+ - lib/relaton_iso_bib/structured_identifier.rb
206
+ - lib/relaton_iso_bib/typed_title_string.rb
207
+ - lib/relaton_iso_bib/version.rb
208
+ - lib/relaton_iso_bib/xml_parser.rb
209
+ - relaton_iso_bib.gemspec
210
+ homepage: https://github.com/metanorma/relaton-iso-bib
211
+ licenses:
212
+ - BSD-2-Clause
213
+ metadata: {}
214
+ post_install_message:
215
+ rdoc_options: []
216
+ require_paths:
217
+ - lib
218
+ required_ruby_version: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ required_rubygems_version: !ruby/object:Gem::Requirement
224
+ requirements:
225
+ - - ">="
226
+ - !ruby/object:Gem::Version
227
+ version: '0'
228
+ requirements: []
229
+ rubyforge_project:
230
+ rubygems_version: 2.6.12
231
+ signing_key:
232
+ specification_version: 4
233
+ summary: 'RelatonIsoBib: Ruby ISOXMLDOC impementation.'
234
+ test_files: []