relaton-w3c 1.0.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,11 @@
1
1
  module RelatonW3c
2
2
  class HashConverter < RelatonBib::HashConverter
3
+ class << self
4
+ # @param item_hash [Hash]
5
+ # @return [RelatonW3c::W3cBibliographicItem]
6
+ def bib_item(item_hash)
7
+ W3cBibliographicItem.new item_hash
8
+ end
9
+ end
3
10
  end
4
11
  end
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "fileutils"
4
+ require "yaml"
5
+
3
6
  module RelatonW3c
4
7
  # Page of hit collection.
5
8
  class HitCollection < RelatonBib::HitCollection
@@ -44,7 +44,7 @@ module RelatonW3c
44
44
  titles << { content: title, type: "main" }
45
45
  subtitle = doc.at("//h2[@id='subtitle']").text
46
46
  titles << { content: subtitle, tipe: "subtitle" }
47
- else
47
+ elsif hit["title"]
48
48
  titles << { content: hit["title"], type: "main" }
49
49
  end
50
50
  titles.map do |t|
@@ -166,7 +166,7 @@ module RelatonW3c
166
166
 
167
167
  hit = { "link" => link }
168
168
  item = parse_page hit
169
- [RelatonBib::DocumentRelation.new(type: "obsoleted", bibitem: item)]
169
+ [RelatonBib::DocumentRelation.new(type: "obsoletedBy", bibitem: item)]
170
170
  end
171
171
 
172
172
  # @param doc [Nokogiri::HTML::Document]
@@ -1,3 +1,3 @@
1
1
  module RelatonW3c
2
- VERSION = "1.0.0".freeze
2
+ VERSION = "1.3.0".freeze
3
3
  end
@@ -5,35 +5,12 @@ module RelatonW3c
5
5
  proposedRecommendation recommendation retired workingDraft
6
6
  ].freeze
7
7
 
8
- attr_reader :doctype
9
-
10
8
  # @param doctype [String]
11
9
  def initialize(**args)
12
10
  if args[:doctype] && !TYPES.include?(args[:doctype])
13
11
  warn "[relaton-w3c] invalid document type: #{args[:doctype]}"
14
12
  end
15
- @doctype = args.delete :doctype
16
13
  super **args
17
14
  end
18
-
19
- # @param builder [Nokogiri::XML::Builder, NilClass]
20
- # @param opts [Hash]
21
- # @option opts [TrueClass, FalseClass, NilClass] bibdata
22
- def to_xml(builder = nil, **opts)
23
- super builder, **opts do |b|
24
- if opts[:bibdata] && doctype
25
- b.ext do |e|
26
- e.doctype doctype if doctype
27
- end
28
- end
29
- end
30
- end
31
-
32
- # @return [Hash]
33
- def to_hash
34
- hash = super
35
- hash["doctype"] = doctype if doctype
36
- hash
37
- end
38
15
  end
39
16
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "net/http"
4
+
3
5
  module RelatonW3c
4
6
  # Class methods for search W3C standards.
5
7
  class W3cBibliography
@@ -10,7 +12,7 @@ module RelatonW3c
10
12
  HitCollection.new text
11
13
  rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET,
12
14
  EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
13
- Net::ProtocolError, OpenSSL::SSL::SSLError, Errno::ETIMEDOUT
15
+ Net::ProtocolError, Errno::ETIMEDOUT
14
16
  raise RelatonBib::RequestError,
15
17
  "Could not access #{HitCollection::DOMAIN}"
16
18
  end
@@ -1,19 +1,6 @@
1
1
  module RelatonW3c
2
2
  class XMLParser < RelatonBib::XMLParser
3
3
  class << self
4
- # @param xml [String]
5
- # @return [RelatonW3c::W3cBibliographicItem, NilClass]
6
- def from_xml(xml)
7
- doc = Nokogiri::XML xml
8
- doc.remove_namespaces!
9
- item = doc.at("/bibitem|/bibdata")
10
- if item
11
- W3cBibliographicItem.new(item_data(item))
12
- else
13
- warn "[relaton-w3c] can't find bibitem or bibdata element in the XML"
14
- end
15
- end
16
-
17
4
  private
18
5
 
19
6
  # Override RelatonBib::XMLParser.item_data method.
@@ -27,6 +14,12 @@ module RelatonW3c
27
14
  data[:doctype] = ext.at("./doctype")&.text
28
15
  data
29
16
  end
17
+
18
+ # @param item_hash [Hash]
19
+ # @return [RelatonBib::BibliographicItem]
20
+ def bib_item(item_hash)
21
+ W3cBibliographicItem.new item_hash
22
+ end
30
23
  end
31
24
  end
32
25
  end
@@ -9,9 +9,9 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ["open.source@ribose.com"]
10
10
 
11
11
  spec.summary = "RelatonIso: retrieve W3C Standards for bibliographic "\
12
- "use using the IsoBibliographicItem model"
12
+ "using the IsoBibliographicItem model"
13
13
  spec.description = "RelatonIso: retrieve W3C Standards for bibliographic "\
14
- "use using the IsoBibliographicItem model"
14
+ "using the IsoBibliographicItem model"
15
15
  spec.homepage = "https://github.com/relaton/relaton-wc3"
16
16
  spec.license = "BSD-2-Clause"
17
17
  spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
@@ -39,5 +39,5 @@ Gem::Specification.new do |spec|
39
39
  spec.add_development_dependency "vcr"
40
40
  spec.add_development_dependency "webmock"
41
41
 
42
- spec.add_dependency "relaton-bib", ">= 1.0.0"
42
+ spec.add_dependency "relaton-bib", ">= 1.3.0"
43
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-w3c
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-25 00:00:00.000000000 Z
11
+ date: 2020-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: debase
@@ -114,15 +114,15 @@ dependencies:
114
114
  requirements:
115
115
  - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: 1.0.0
117
+ version: 1.3.0
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: 1.0.0
125
- description: 'RelatonIso: retrieve W3C Standards for bibliographic use using the IsoBibliographicItem
124
+ version: 1.3.0
125
+ description: 'RelatonIso: retrieve W3C Standards for bibliographic using the IsoBibliographicItem
126
126
  model'
127
127
  email:
128
128
  - open.source@ribose.com
@@ -144,6 +144,8 @@ files:
144
144
  - bin/console
145
145
  - bin/rspec
146
146
  - bin/setup
147
+ - grammars/basicdoc.rng
148
+ - grammars/biblio.rng
147
149
  - lib/relaton_w3c.rb
148
150
  - lib/relaton_w3c/hash_converter.rb
149
151
  - lib/relaton_w3c/hit.rb
@@ -178,6 +180,6 @@ requirements: []
178
180
  rubygems_version: 3.0.6
179
181
  signing_key:
180
182
  specification_version: 4
181
- summary: 'RelatonIso: retrieve W3C Standards for bibliographic use using the IsoBibliographicItem
183
+ summary: 'RelatonIso: retrieve W3C Standards for bibliographic using the IsoBibliographicItem
182
184
  model'
183
185
  test_files: []