relaton-bib 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c724b4c6147f9e16ec7af1ec4097134731a812a
4
- data.tar.gz: 22c2e36e0b2f775f1e467f687b5145ab6780b915
3
+ metadata.gz: 2652e6a30640ef8035238e6ae6126063b9057890
4
+ data.tar.gz: 03f6a59bf6dd3d152578073e55d5d35b235bfc34
5
5
  SHA512:
6
- metadata.gz: ca64daeace4b61699af94a1447395fa8824f093e676587a81f7e36437dc22c9684b9fdfa2aa19f500932859ebf888f8a37f3228054a1274fab886fdcc86cfdc3
7
- data.tar.gz: e2818b0ffce974cbac83e445d7665902696cecbe3b068727caa85065459b710a377b17156a9809150dcdf0574325ae57a7cccd1744458e60a7507907de723308
6
+ metadata.gz: 6ead52473fc5af8a5c86d9fce36bc048f383c3740c2047a7fd7bfc26cfd3f6211587842a0a5add6cdc7d1060e4d9d1d6f167b4e20fb751f8482f3c2a53be2e68
7
+ data.tar.gz: 540bccaead183468e59e4ea8b3edc64352d1d1df1c12ca6f3a09e4e8f7c3c2f891681490a5f7d548412833dcdc9c05b96839e8a134306b1e464d92041148e863
@@ -1,15 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- relaton-bib (0.3.5)
4
+ relaton-bib (0.3.6)
5
5
  addressable
6
- nokogiri (~> 1.10)
6
+ nokogiri
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- addressable (2.6.0)
12
- public_suffix (>= 2.0.2, < 4.0)
11
+ addressable (2.7.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
13
  byebug (11.0.1)
14
14
  debase (0.2.3)
15
15
  debase-ruby_core_source (>= 0.10.2)
@@ -22,7 +22,7 @@ GEM
22
22
  mini_portile2 (2.4.0)
23
23
  nokogiri (1.10.3)
24
24
  mini_portile2 (~> 2.4.0)
25
- public_suffix (3.1.1)
25
+ public_suffix (4.0.1)
26
26
  rake (10.5.0)
27
27
  rspec (3.8.0)
28
28
  rspec-core (~> 3.8.0)
@@ -1,11 +1,31 @@
1
1
  require "relaton_bib/version"
2
2
  require "relaton_bib/bibliographic_item"
3
+ require "relaton_bib/hit_collection"
4
+ require "relaton_bib/hit"
3
5
 
4
6
  module RelatonBib
5
7
  class Error < StandardError; end
6
8
 
7
9
  class RequestError < StandardError; end
8
10
 
11
+ class << self
12
+ # @param date [String]
13
+ # @return [Date, NilClass]
14
+ def parse_date(sdate)
15
+ if /(?<date>\w+\s\d{4})/ =~ sdate # February 2012
16
+ Date.strptime(date, "%B %Y")
17
+ elsif /(?<date>\w+\s\d{1,2},\s\d{4})/ =~ sdate # February 11, 2012
18
+ Date.strptime(date, "%B %d, %Y")
19
+ elsif /(?<date>\d{4}-\d{2}-\d{2})/ =~ sdate # 2012-02-11
20
+ Date.parse(date)
21
+ elsif /(?<date>\d{4}-\d{2})/ =~ sdate # 2012-02
22
+ Date.strptime date, "%Y-%m"
23
+ elsif /(?<date>\d{4})/ =~ sdate # 2012
24
+ Date.strptime date, "%Y"
25
+ end
26
+ end
27
+ end
28
+
9
29
  private
10
30
 
11
31
  # @param array [Array]
@@ -22,18 +22,18 @@ module RelatonBib
22
22
  attr_reader :on
23
23
 
24
24
  # @param type [String] "published", "accessed", "created", "activated"
25
+ # @param on [String]
25
26
  # @param from [String]
26
27
  # @param to [String]
27
28
  def initialize(type:, on: nil, from: nil, to: nil)
28
29
  raise ArgumentError, "expected :on or :from argument" unless on || from
29
30
 
30
- TYPES.include?(type) or
31
- raise ArgumentError, %{Type "#{type}" is invalid.} unless
31
+ raise ArgumentError, "invalid type: #{type}" unless TYPES.include? type
32
32
 
33
33
  @type = type
34
- @on = parse_date on
35
- @from = parse_date from
36
- @to = parse_date to
34
+ @on = RelatonBib.parse_date on
35
+ @from = RelatonBib.parse_date from
36
+ @to = RelatonBib.parse_date to
37
37
  end
38
38
 
39
39
  # rubocop:disable Metrics/AbcSize
@@ -74,19 +74,5 @@ module RelatonBib
74
74
  else date.year
75
75
  end
76
76
  end
77
-
78
- # @params date [String] 'yyyy', 'yyyy-mm', 'yyyy-mm-dd
79
- # @return [Date]
80
- def parse_date(date)
81
- return unless date
82
-
83
- if date =~ /^\d{4}$/
84
- Date.strptime date, "%Y"
85
- elsif date =~ /^\d{4}-\d{2}$/
86
- Date.strptime date, "%Y-%m"
87
- elsif date =~ /\d{4}-\d{2}-\d{2}$/
88
- Date.strptime date, "%Y-%m-%d"
89
- end
90
- end
91
77
  end
92
78
  end
@@ -210,7 +210,7 @@ module RelatonBib
210
210
  @language = args.fetch :language, []
211
211
  @script = args.fetch :script, []
212
212
  @status = args[:docstatus]
213
- @relation = DocRelationCollection.new(args[:relation] || [])
213
+ @relation = DocRelationCollection.new(args[:relation] || [])
214
214
  @link = args.fetch(:link, []).map { |s| s.is_a?(Hash) ? TypedUri.new(s) : s }
215
215
  @series = args.fetch :series, []
216
216
  @medium = args[:medium]
@@ -29,7 +29,7 @@ module RelatonBib
29
29
  # @param builder [Nokogiri::XML::Builder]
30
30
  def to_xml(builder)
31
31
  builder.copyright do
32
- builder.from from ? from.year : "copyright year unknown"
32
+ builder.from from ? from.year : "unknown"
33
33
  builder.to to.year if to
34
34
  builder.owner { owner.to_xml builder }
35
35
  end
@@ -139,8 +139,8 @@ module RelatonBib
139
139
  roles = array(ret[:contributor][i][:role]).map do |r|
140
140
  if r.is_a? Hash
141
141
  { type: r[:type], description: array(r[:description]) }
142
- elsif r.is_a? Array
143
- { type: r[0], description: r.fetch(1) }
142
+ # elsif r.is_a? Array
143
+ # { type: r[0], description: r.fetch(1) }
144
144
  else
145
145
  { type: r }
146
146
  end
@@ -0,0 +1,32 @@
1
+ module RelatonBib
2
+ class Hit
3
+ # @return [Array<Hash>]
4
+ attr_reader :hit
5
+
6
+ # @param hit [Hash]
7
+ # @param hit_collection [RelatonNist:HitCollection]
8
+ def initialize(hit, hit_collection = nil)
9
+ @hit = hit
10
+ @hit_collection = hit_collection
11
+ end
12
+
13
+ # @return [String]
14
+ def to_s
15
+ inspect
16
+ end
17
+
18
+ # @return [String]
19
+ def inspect
20
+ "<#{self.class}:#{format('%#.14x', object_id << 1)} "\
21
+ "@text=\"#{@hit_collection&.text}\" "\
22
+ "@fetched=\"#{!@fetch.nil?}\" "\
23
+ "@fullIdentifier=\"#{@fetch&.shortref(nil)}\" "\
24
+ "@title=\"#{@hit[:code]}\">"
25
+ end
26
+
27
+ # @return [String]
28
+ def to_xml(**opts)
29
+ fetch.to_xml **opts
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,34 @@
1
+ module RelatonBib
2
+ class HitCollection < Array
3
+ # @return [TrueClass, FalseClass]
4
+ attr_reader :fetched
5
+
6
+ # @return [String]
7
+ attr_reader :text
8
+
9
+ # @return [String]
10
+ attr_reader :year
11
+
12
+ # @return [Iecbib::HitCollection]
13
+ def fetch
14
+ workers = WorkersPool.new 4
15
+ workers.worker(&:fetch)
16
+ each do |hit|
17
+ workers << hit
18
+ end
19
+ workers.end
20
+ workers.result
21
+ @fetched = true
22
+ self
23
+ end
24
+
25
+ def to_s
26
+ inspect
27
+ end
28
+
29
+ # @return [String]
30
+ def inspect
31
+ "<#{self.class}:#{format('%#.14x', object_id << 1)} @fetched=#{@fetched}>"
32
+ end
33
+ end
34
+ end
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "0.3.5".freeze
2
+ VERSION = "0.3.6".freeze
3
3
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
 
11
11
  spec.summary = "RelatonBib: Ruby XMLDOC impementation."
12
12
  spec.description = "RelatonBib: Ruby XMLDOC impementation."
13
- spec.homepage = "https://github.com/metanorma/relaton-item"
13
+ spec.homepage = "https://github.com/relaton/relaton-item"
14
14
  spec.license = "BSD-2-Clause"
15
15
 
16
16
  # Specify which files should be added to the gem when it is released.
@@ -33,5 +33,5 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency "byebug"
34
34
 
35
35
  spec.add_dependency "addressable"
36
- spec.add_dependency "nokogiri", "~> 1.10"
36
+ spec.add_dependency "nokogiri"
37
37
  end
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.5
4
+ version: 0.3.6
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-08-20 00:00:00.000000000 Z
11
+ date: 2019-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -140,16 +140,16 @@ dependencies:
140
140
  name: nokogiri
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - "~>"
143
+ - - ">="
144
144
  - !ruby/object:Gem::Version
145
- version: '1.10'
145
+ version: '0'
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - "~>"
150
+ - - ">="
151
151
  - !ruby/object:Gem::Version
152
- version: '1.10'
152
+ version: '0'
153
153
  description: 'RelatonBib: Ruby XMLDOC impementation.'
154
154
  email:
155
155
  - open.source@ribose.com
@@ -188,6 +188,8 @@ files:
188
188
  - lib/relaton_bib/formatted_string.rb
189
189
  - lib/relaton_bib/hash_converter.rb
190
190
  - lib/relaton_bib/hash_to_bib.rb
191
+ - lib/relaton_bib/hit.rb
192
+ - lib/relaton_bib/hit_collection.rb
191
193
  - lib/relaton_bib/localized_string.rb
192
194
  - lib/relaton_bib/medium.rb
193
195
  - lib/relaton_bib/organization.rb
@@ -200,7 +202,7 @@ files:
200
202
  - lib/relaton_bib/workers_pool.rb
201
203
  - lib/relaton_bib/xml_parser.rb
202
204
  - relaton-bib.gemspec
203
- homepage: https://github.com/metanorma/relaton-item
205
+ homepage: https://github.com/relaton/relaton-item
204
206
  licenses:
205
207
  - BSD-2-Clause
206
208
  metadata: {}