relaton-3gpp 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,244 @@
1
+ module Relaton3gpp
2
+ class Parser
3
+ #
4
+ # Document parser initalization
5
+ #
6
+ # @param [Hash] row row
7
+ # @param [Array<Hash>] specrels Spec + Release table
8
+ # @param [Array<Hash>] relaeases Releases table
9
+ # @param [Array<Hash>] specs Specs table
10
+ #
11
+ def initialize(row, specs, specrels, releases) # rubocop:disable Metrics/AbcSize
12
+ @row = row
13
+ @spec = specs.detect { |s| s[:Number] == row[:spec] }
14
+ if @spec
15
+ @specrel = specrels.detect do |sr|
16
+ sr[:Spec] == row[:spec] && sr[:Release] == row[:release]
17
+ end
18
+ @rel = releases.detect { |r| r[:Release_code] == row[:release] }
19
+ end
20
+ end
21
+
22
+ #
23
+ # Initialize document parser and run it
24
+ #
25
+ # @param [Hash] row row
26
+ # @param [Array<Hash>] specrels Spec + Release table
27
+ # @param [Array<Hash>] relaeases Releases table
28
+ # @param [Array<Hash>] specs Specs table
29
+ #
30
+ # @return [RelatonBib:BibliographicItem, nil] bibliographic item
31
+ #
32
+ def self.parse(row, specs, specrels, relaeases)
33
+ new(row, specs, specrels, relaeases).parse
34
+ end
35
+
36
+ #
37
+ # Parse document
38
+ #
39
+ # @return [Relaton3gpp:BibliographicItem, nil] bibliographic item
40
+ #
41
+ def parse # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
42
+ return unless @spec && @row[:"3guId"]
43
+
44
+ Relaton3gpp::BibliographicItem.new(
45
+ type: "standard",
46
+ fetched: Date.today.to_s,
47
+ language: ["en"],
48
+ script: ["Latn"],
49
+ title: parse_title,
50
+ link: parse_link,
51
+ abstract: parse_abstract,
52
+ docid: parse_docid,
53
+ docnumber: number,
54
+ date: parse_date,
55
+ doctype: @spec[:Type],
56
+ editorialgroup: parse_editorialgroup,
57
+ biblionote: parse_note,
58
+ docstatus: parse_status,
59
+ radiotechnology: parse_radiotechnology,
60
+ common_ims_spec: @spec[:ComIMS] == "1",
61
+ # internal: @spec[:"For publication"] == "0",
62
+ release: parse_release,
63
+ # contributor: contributor,
64
+ )
65
+ end
66
+
67
+ #
68
+ # Parse title
69
+ #
70
+ # @return [RelatonBib::TypedTitleStringCollection] title
71
+ #
72
+ def parse_title
73
+ t = RelatonBib::TypedTitleString.new content: @spec[:Title], type: "main"
74
+ RelatonBib::TypedTitleStringCollection.new [t]
75
+ end
76
+
77
+ #
78
+ # Parse link
79
+ #
80
+ # @return [Array<RelatonBib::TypedUri>] link
81
+ #
82
+ def parse_link
83
+ return [] unless @row[:location]
84
+
85
+ content = @row[:location].split("#").last
86
+ [RelatonBib::TypedUri.new(type: "src", content: content)]
87
+ end
88
+
89
+ #
90
+ # Parse abstract
91
+ #
92
+ # @return [Array<RelatonBib::FormattedString>]
93
+ #
94
+ def parse_abstract
95
+ return [] unless @spec[:description]
96
+
97
+ [RelatonBib::FormattedString.new(content: @spec[:description])]
98
+ end
99
+
100
+ #
101
+ # Parse docidentifier
102
+ #
103
+ # @return [Arra<RelatonBib::DocumentIdentifier>] docidentifier
104
+ #
105
+ def parse_docid
106
+ [
107
+ RelatonBib::DocumentIdentifier.new(type: "3GPP", id: "3GPP #{number}"),
108
+ RelatonBib::DocumentIdentifier.new(type: "rapporteurId",
109
+ id: @spec[:"rapporteur id"]),
110
+ ]
111
+ end
112
+
113
+ #
114
+ # Generate number
115
+ #
116
+ # @return [String] number
117
+ #
118
+ def number
119
+ "#{@spec[:Type]} #{@row[:spec]}:#{@row[:release]}/#{version}"
120
+ end
121
+
122
+ #
123
+ # Version
124
+ #
125
+ # @return [String] version
126
+ #
127
+ def version
128
+ "#{@row[:MAJOR_VERSION_NB]}.#{@row[:TECHNICAL_VERSION_NB]}.#{@row[:EDITORIAL_VERSION_NB]}"
129
+ end
130
+
131
+ #
132
+ # Parse date
133
+ #
134
+ # @return [Array<RelatonBib::BibliographicDate>] date
135
+ #
136
+ def parse_date
137
+ d = []
138
+ if @row[:completed]
139
+ cd = Date.parse(@row[:completed]).to_s
140
+ d << RelatonBib::BibliographicDate.new(type: "created", on: cd)
141
+ end
142
+ if @spec[:"title verified"]
143
+ td = Date.parse(@spec[:"title verified"]).to_s
144
+ d << RelatonBib::BibliographicDate.new(type: "confirmed", on: td)
145
+ end
146
+ d
147
+ end
148
+
149
+ #
150
+ # Parse editorialgroup
151
+ #
152
+ # @return [RelatonBib::EditorialGroup] editorialgroups
153
+ #
154
+ def parse_editorialgroup # rubocop:disable Metrics/MethodLength
155
+ wgp = RelatonBib::WorkGroup.new(name: @spec[:"WG prime"], type: "prime")
156
+ eg = [RelatonBib::TechnicalCommittee.new(wgp)]
157
+ if @spec[:"WG other"]
158
+ wgo = RelatonBib::WorkGroup.new(name: @spec[:"WG other"], type: "other")
159
+ eg << RelatonBib::TechnicalCommittee.new(wgo)
160
+ end
161
+ if @spec[:"former WG"]
162
+ wgf = RelatonBib::WorkGroup.new(name: @spec[:"former WG"], type: "former")
163
+ eg << RelatonBib::TechnicalCommittee.new(wgf)
164
+ end
165
+ RelatonBib::EditorialGroup.new eg
166
+ end
167
+
168
+ #
169
+ # Parse note
170
+ #
171
+ # @return [RelatonBib::BiblioNoteCollection] notes
172
+ #
173
+ def parse_note
174
+ n = []
175
+ if @specrel && @specrel[:remarks]
176
+ n << RelatonBib::BiblioNote.new(type: "remark", content: @specrel[:remarks])
177
+ end
178
+ if @row[:comment]
179
+ n << RelatonBib::BiblioNote.new(type: "comment", content: @row[:comment])
180
+ end
181
+ RelatonBib::BiblioNoteCollection.new n
182
+ end
183
+
184
+ #
185
+ # Prase status
186
+ #
187
+ # @return [RelatnoBib::DocumentStatus, nil] status
188
+ #
189
+ def parse_status
190
+ if @specrel && @specrel[:withdrawn] == "1"
191
+ RelatonBib::DocumentStatus.new stage: "withdrawn"
192
+ elsif @spec[:"For publication"] == "1"
193
+ RelatonBib::DocumentStatus.new stage: "published"
194
+ end
195
+ end
196
+
197
+ #
198
+ # Parse radio technology
199
+ #
200
+ # @return [String] radio technology
201
+ #
202
+ def parse_radiotechnology
203
+ if @spec[:"2g"] == "1" then "2G"
204
+ elsif @spec[:"3g"] == "1" then "3G"
205
+ elsif @spec[:LTE] == "1" then "LTE"
206
+ elsif @spec[:"5G"] == "1" then "5G"
207
+ end
208
+ end
209
+
210
+ def parse_release # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
211
+ if @rel
212
+ project_start = Date.parse(@rel[:"rel-proj-start"]).to_s if @rel[:"rel-proj-start"]
213
+ project_end = Date.parse(@rel[:"rel-proj-end"]).to_s if @rel[:"rel-proj-end"]
214
+ end
215
+ Release.new(
216
+ version2g: @rel[:version_2g],
217
+ version3g: @rel[:version_3g],
218
+ defunct: @rel[:defunct] == "1",
219
+ wpm_code_2g: @rel[:wpm_code_2g],
220
+ wpm_code_3g: @rel[:wpm_code_3g],
221
+ freeze_meeting: @rel[:"freeze meeting"],
222
+ freeze_stage1_meeting: @rel[:Stage1_freeze],
223
+ freeze_stage2_meeting: @rel[:Stage2_freeze],
224
+ freeze_stage3_meeting: @rel[:Stage3_freeze],
225
+ close_meeting: @rel[:Closed],
226
+ project_start: project_start,
227
+ project_end: project_end,
228
+ )
229
+ end
230
+
231
+ #
232
+ # Create contributor
233
+ #
234
+ # @return [Array<RelatonBib::Contribution>] contributor
235
+ #
236
+ # def contributor
237
+ # org = RelatonBib::Organization.new(
238
+ # name: "Internet Assigned Numbers Authority", abbreviation: "IANA",
239
+ # )
240
+ # role = { type: "publisher" }
241
+ # [RelatonBib::ContributionInfo.new(entity: org, role: [role])]
242
+ # end
243
+ end
244
+ end
@@ -0,0 +1,54 @@
1
+ require "relaton/processor"
2
+
3
+ module Relaton3gpp
4
+ class Processor < Relaton::Processor
5
+ attr_reader :idtype
6
+
7
+ def initialize # rubocop:disable Lint/MissingSuper
8
+ @short = :relaton_3gpp
9
+ @prefix = "3GPP"
10
+ @defaultprefix = %r{^3GPP\s}
11
+ @idtype = "3GPP"
12
+ @datasets = %w[status-smg-3GPP]
13
+ end
14
+
15
+ # @param code [String]
16
+ # @param date [String, NilClass] year
17
+ # @param opts [Hash]
18
+ # @return [RelatonBib::BibliographicItem]
19
+ def get(code, date, opts)
20
+ ::Relaton3gpp::Bibliography.get(code, date, opts)
21
+ end
22
+
23
+ #
24
+ # Fetch all the documents from http://xml2rfc.tools.ietf.org/public/rfc/bibxml-3gpp-new/
25
+ #
26
+ # @param [String] _source source name
27
+ # @param [Hash] opts
28
+ # @option opts [String] :output directory to output documents
29
+ # @option opts [String] :format
30
+ #
31
+ def fetch_data(_source, opts)
32
+ DataFetcher.fetch(**opts)
33
+ end
34
+
35
+ # @param xml [String]
36
+ # @return [RelatonBib::BibliographicItem]
37
+ def from_xml(xml)
38
+ ::Relaton3gpp::XMLParser.from_xml xml
39
+ end
40
+
41
+ # @param hash [Hash]
42
+ # @return [RelatonBib::BibliographicItem]
43
+ def hash_to_bib(hash)
44
+ item_hash = ::Relaton3gpp::HashConverter.hash_to_bib(hash)
45
+ ::Relaton3gpp::BibliographicItem.new(**item_hash)
46
+ end
47
+
48
+ # Returns hash of XML grammar
49
+ # @return [String]
50
+ def grammar_hash
51
+ @grammar_hash ||= ::Relaton3gpp.grammar_hash
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,65 @@
1
+ module Relaton3gpp
2
+ class Release
3
+ #
4
+ # Initialize release.
5
+ #
6
+ # @param [String] version2g
7
+ # @param [String] version3g
8
+ # @param [Boolean] defunct
9
+ # @param [String] wpn_code_2g
10
+ # @param [String] wpn_code_3g
11
+ # @param [String] freeze_stage1_meeting
12
+ # @param [String] freeze_stage2_meeting
13
+ # @param [String] freeze_stage3_meeting
14
+ # @param [String] close_meeting
15
+ # @param [String] project_start
16
+ # @param [String] project_end
17
+ #
18
+ def initialize(**args) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
19
+ @version2g = args[:version2g]
20
+ @version3g = args[:version3g]
21
+ @defunct = args[:defunct]
22
+ @wpm_code_2g = args[:wpm_code_2g]
23
+ @wpm_code_3g = args[:wpm_code_3g]
24
+ @freeze_meeting = args[:freeze_meeting]
25
+ @freeze_stage1_meeting = args[:freeze_stage1_meeting]
26
+ @freeze_stage2_meeting = args[:freeze_stage2_meeting]
27
+ @freeze_stage3_meeting = args[:freeze_stage3_meeting]
28
+ @close_meeting = args[:close_meeting]
29
+ @project_start = args[:project_start]
30
+ @project_end = args[:project_end]
31
+ end
32
+
33
+ #
34
+ # Render XML.
35
+ #
36
+ # @param [Nokogiri::XML::Builder] builder
37
+ #
38
+ def to_xml(builder) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
39
+ builder.release do
40
+ builder.version2G @version2g if @version2g
41
+ builder.version3G @version3g if @version3g
42
+ builder.defunct @defunct if @defunct
43
+ builder.send "wpm-code-2G", @wpm_code_2g if @wpm_code_2g
44
+ builder.send "wpm-code-3G", @wpm_code_3g if @wpm_code_3g
45
+ builder.send "freeze-meeting", @freeze_meeting if @freeze_meeting
46
+ builder.send "freeze-stage1-meeting", @freeze_stage1_meeting if @freeze_stage1_meeting
47
+ builder.send "freeze-stage2-meeting", @freeze_stage2_meeting if @freeze_stage2_meeting
48
+ builder.send "freeze-stage3-meeting", @freeze_stage3_meeting if @freeze_stage3_meeting
49
+ builder.send "close-meeting", @close_meeting if @close_meeting
50
+ builder.send "project-start", @project_start if @project_start
51
+ builder.send "project-end", @project_end if @project_end
52
+ end
53
+ end
54
+
55
+ def to_hash
56
+ hash = {}
57
+ instance_variables.each do |var|
58
+ unless instance_variable_get(var).nil?
59
+ hash[var.to_s.delete("@")] = instance_variable_get var
60
+ end
61
+ end
62
+ hash
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Relaton3gpp
4
+ VERSION = "1.9.0"
5
+ end
@@ -0,0 +1,58 @@
1
+ module Relaton3gpp
2
+ class XMLParser < RelatonBib::XMLParser
3
+ class << self
4
+ private
5
+
6
+ #
7
+ # Parse XML to hash
8
+ #
9
+ # @param [Nokofiri::XML::Element] bibitem
10
+ #
11
+ # @return [Hash]
12
+ #
13
+ def item_data(bibitem)
14
+ hash = super
15
+ ext = bibitem.at "./ext"
16
+ if ext
17
+ hash[:radiotechnology] = ext.at("./radiotechnology")&.text
18
+ hash[:common_ims_spec] = ext.at("./common-ims-spec")&.text
19
+ hash[:release] = fetch_release(ext)
20
+ end
21
+ hash
22
+ end
23
+
24
+ #
25
+ # Ftech release information
26
+ #
27
+ # @param [Nokogiri::XML::Element] ext
28
+ #
29
+ # @return [Relaton3gpp::Release] release
30
+ #
31
+ def fetch_release(ext) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
32
+ release = ext.at("./release")
33
+ return unless release
34
+
35
+ hash = {}
36
+ hash[:version2g] = release.at("./version2G")&.text
37
+ hash[:version3g] = release.at("./version3G")&.text
38
+ hash[:defunct] = release.at("./defunct")&.text
39
+ hash[:wpm_code_2g] = release.at("./wpm-code-2G")&.text
40
+ hash[:wpm_code_3g] = release.at("./wpm-code-3G")&.text
41
+ hash[:freeze_meeting] = release.at("./freeze-meeting")&.text
42
+ hash[:freeze_stage1_meeting] = release.at("./freeze-stage1-meeting")&.text
43
+ hash[:freeze_stage2_meeting] = release.at("./freeze-stage2-meeting")&.text
44
+ hash[:freeze_stage3_meeting] = release.at("./freeze-stage3-meeting")&.text
45
+ hash[:close_meeting] = release.at("./close-meeting")&.text
46
+ hash[:project_start] = release.at("./project-start")&.text
47
+ hash[:project_end] = release.at("./project-end")&.text
48
+ Release.new(**hash)
49
+ end
50
+
51
+ # @param item_hash [Hash]
52
+ # @return [RelatonSgpp::BibliographicItem]
53
+ def bib_item(item_hash)
54
+ BibliographicItem.new(**item_hash)
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "relaton_bib"
5
+ require_relative "relaton_3gpp/version"
6
+ require_relative "relaton_3gpp/release"
7
+ require_relative "relaton_3gpp/bibliographic_item"
8
+ require_relative "relaton_3gpp/hash_converter"
9
+ require_relative "relaton_3gpp/xml_parser"
10
+ require_relative "relaton_3gpp/bibliography"
11
+ require_relative "relaton_3gpp/parser"
12
+ require_relative "relaton_3gpp/data_fetcher"
13
+
14
+ module Relaton3gpp
15
+ class Error < StandardError; end
16
+
17
+ # Returns hash of XML reammar
18
+ # @return [String]
19
+ def self.grammar_hash
20
+ gem_path = File.expand_path "..", __dir__
21
+ grammars_path = File.join gem_path, "grammars", "*"
22
+ grammars = Dir[grammars_path].sort.map { |gp| File.read gp }.join
23
+ Digest::MD5.hexdigest grammars
24
+ end
25
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/relaton_3gpp/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "relaton-3gpp"
7
+ spec.version = Relaton3gpp::VERSION
8
+ spec.authors = ["Ribose Inc."]
9
+ spec.email = ["open.source@ribose.com"]
10
+
11
+ spec.summary = "RelatonIana: Ruby XMLDOC impementation."
12
+ spec.description = "RelatonIana: Ruby XMLDOC impementation."
13
+ spec.homepage = "https://github.com/relaton/relaton-iana"
14
+ spec.license = "BSD-2-Clause"
15
+ spec.required_ruby_version = ">= 2.5.0"
16
+
17
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'https://mygemserver.com'"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+
21
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
22
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ # Uncomment to register a new dependency of your gem
34
+ # spec.add_dependency "example-gem", "~> 1.0"
35
+
36
+ # For more information and examples about making a new gem, checkout our
37
+ # guide at: https://bundler.io/guides/creating_gem.html
38
+ spec.add_development_dependency "equivalent-xml", "~> 0.6"
39
+ spec.add_development_dependency "rubocop", "~> 1.23.0"
40
+ spec.add_development_dependency "rubocop-performance", "~> 1.12.0"
41
+ spec.add_development_dependency "rubocop-rails", "~> 2.12.0"
42
+ spec.add_development_dependency "ruby-jing", "~> 0.0.2"
43
+ spec.add_development_dependency "simplecov", "~> 0.21.2"
44
+ spec.add_development_dependency "vcr", "~> 6.0.0"
45
+ spec.add_development_dependency "webmock", "~> 3.14.0"
46
+
47
+ spec.add_dependency "mdb", "~> 0.5.0"
48
+ spec.add_dependency "relaton-bib", "~> 1.9.0"
49
+ spec.add_dependency "rubyzip", "~> 2.3.0"
50
+ end