relaton-bib 0.1.2 → 0.1.3

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: 98577d6e08bf18ceb7bbd5d3f050e472b580605a
4
- data.tar.gz: cda0642e266ecb7e639a971d0b4df918b692a403
3
+ metadata.gz: 60bb4874a237284708c425732d7444c96f3e75ee
4
+ data.tar.gz: d3f58322324888ca1828e815b8fe4bae16e24470
5
5
  SHA512:
6
- metadata.gz: ee7ec704250e9a966fc6b85d18bdb961781659f9896ea4e6973d8d5c7b741cb7bc9b5e68af1684c4176308fd67aa7e88a12e8f6cb989f46fce9e6451e6413c32
7
- data.tar.gz: a0038770adb2d4dff2bed71a45e2f801ef0f5d384170f704a393a36752d53069b065fa1052e93bd7b2f816b2828a48eff3c11e53fd8957a287fbfe6b12e2cf25
6
+ metadata.gz: 4cc9c3a7785ed945d774e1838fa1138c51b311eb8a6987c7616d5338e8feb9d98791a0246408e5214e6b814d21d3785c1a5a52bbbc653e18b2d15cbc7da8234f
7
+ data.tar.gz: 1588562066005b346b7d9bcd424fd41315cc2172d9837e5f886e6382859f9b4066ac707321a0b91dc14ea831eebb4896222b3a5039b5dfaf4aae6cea9909c471
@@ -1,12 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- relaton-bib (0.1.2)
4
+ relaton-bib (0.1.3)
5
+ addressable
5
6
  nokogiri (~> 1.8.4)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
11
+ addressable (2.6.0)
12
+ public_suffix (>= 2.0.2, < 4.0)
10
13
  debase (0.2.2)
11
14
  debase-ruby_core_source (>= 0.10.2)
12
15
  debase-ruby_core_source (0.10.4)
@@ -18,6 +21,7 @@ GEM
18
21
  mini_portile2 (2.3.0)
19
22
  nokogiri (1.8.5)
20
23
  mini_portile2 (~> 2.3.0)
24
+ public_suffix (3.0.3)
21
25
  rake (10.5.0)
22
26
  rspec (3.8.0)
23
27
  rspec-core (~> 3.8.0)
@@ -51,8 +51,9 @@ item = RelatonBib::BibliographicItem.new(
51
51
  ],
52
52
  docnumber: "123456",
53
53
  dates: [
54
+ { type: "issued", on: "2014" },
54
55
  { type: "published", on: "2014-04" },
55
- { type: "accessed", on: "2015" }
56
+ { type: "accessed", on: "2015-05-20" }
56
57
  ],
57
58
  contributors: [
58
59
  { entity: {
@@ -175,11 +176,14 @@ item.to_xml
175
176
  <uri type=\"rss\">https://www.iso.org/contents/data/standard/05/37/53798.detail.rss</uri>
176
177
  <docidentifier type=\"ISO\">TC211</docidentifier>
177
178
  <docnumber>123456</docnumber>
178
- <date type=\"published\">
179
- <on>2014-04</on>
179
+ <date type="issued">
180
+ <on>2014</on>
181
+ </date>
182
+ <date type="published">
183
+ <on>2014</on>
180
184
  </date>
181
- <date type=\"accessed\">
182
- <on>2015-01</on>
185
+ <date type="accessed">
186
+ <on>2015</on>
183
187
  </date>
184
188
  <contributor>
185
189
  <role type=\"publisher\">
@@ -255,6 +259,44 @@ item.to_xml
255
259
  </validity>
256
260
  </bibitem>"
257
261
  ----
262
+ By default date elements are formatted as year (yyyy). Option `:date_format` allows to output date elements in `:short` (yyyy-mm) and `:full` (yyyy-mm-dd) additiona formats.
263
+ [surce,ruby]
264
+ ----
265
+ item.to_xml date_format: :short
266
+ =>"<bibitem id=\"ISO/TC211\" type=\"standard\">
267
+ <fetched>2019-04-30</fetched>
268
+ <title type=\"main\" language=\"en\" script=\"Latn\">Geographic information</title>
269
+ <title language=\"fr\" script=\"Latn\">Information géographique</title>
270
+ <uri type=\"src\">https://www.iso.org/standard/53798.html</uri>
271
+ <uri type=\"obp\">https://www.iso.org/obp/ui/#!iso:std:53798:en</uri>
272
+ <uri type=\"rss\">https://www.iso.org/contents/data/standard/05/37/53798.detail.rss</uri>
273
+ <docidentifier type=\"ISO\">TC211</docidentifier>
274
+ <docnumber>123456</docnumber>
275
+ <date type="issued">
276
+ <on>2014-01</on>
277
+ </date>
278
+ <date type="published">
279
+ <on>2014-04</on>
280
+ </date>
281
+ <date type="accessed">
282
+ <on>2015-05</on>
283
+ </date>
284
+ ...
285
+
286
+ item.to_xml date_format: :full
287
+ =>"<bibitem id=\"ISO/TC211\" type=\"standard\">
288
+ ...
289
+ <date type="issued">
290
+ <on>2014-01-01</on>
291
+ </date>
292
+ <date type="published">
293
+ <on>2014-04-01</on>
294
+ </date>
295
+ <date type="accessed">
296
+ <on>2015-05-20</on>
297
+ </date>
298
+ ...
299
+ ----
258
300
 
259
301
  == Development
260
302
 
@@ -34,35 +34,38 @@ module RelatonBib
34
34
  @to = parse_date to
35
35
  end
36
36
 
37
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
38
- # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity
37
+ # rubocop:disable Metrics/AbcSize
39
38
 
40
39
  # @param builder [Nokogiri::XML::Builder]
41
40
  # @return [Nokogiri::XML::Builder]
42
41
  def to_xml(builder, **opts)
43
42
  builder.date(type: type) do
44
43
  if on
45
- date = opts[:full_date] ? on.strftime("%Y-%m") : on.year
46
- builder.on(opts[:no_year] ? "--" : date)
44
+ builder.on(opts[:no_year] ? "--" : date_format(on, opts[:date_format]))
47
45
  elsif from
48
- if opts[:full_date]
49
- date_form = from.strftime("%Y-%m")
50
- date_to = to.strftime("%Y-%m") if to
51
- else
52
- date_form = from.year
53
- date_to = to.year if to
54
- end
55
- builder.from(opts[:no_year] ? "--" : date_form)
56
- builder.to date_to if to
46
+ builder.from(opts[:no_year] ? "--" : date_format(from, opts[:date_format]))
47
+ builder.to date_format(to, opts[:date_format]) if to
57
48
  end
58
49
  end
59
50
  end
60
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
61
- # rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity
51
+ # rubocop:enable Metrics/AbcSize
62
52
 
63
53
  private
64
54
 
65
- # @params date [String] 'yyyy' or 'yyyy-mm'
55
+ # Formats date
56
+ # @param date [Time]
57
+ # @param format [Symbol, nil] :full (yyyy-mm-dd), :short (yyyy-mm) or nil (yyyy)
58
+ # @return [String]
59
+ def date_format(date, format = nil)
60
+ case format
61
+ when :short then date.strftime "%Y-%m"
62
+ when :full then date.strftime "%Y-%m-%d"
63
+ else date.year
64
+ end
65
+ end
66
+
67
+ # @params date [String] 'yyyy', 'yyyy-mm', 'yyyy-mm-dd
68
+ # @return [Time]
66
69
  def parse_date(date)
67
70
  return unless date
68
71
 
@@ -281,12 +281,12 @@ module RelatonBib
281
281
 
282
282
  # @param builder [Nokogiri::XML::Builder, NillClass] (nil)
283
283
  # @return [String]
284
- def to_xml(builder = nil, root = "bibitem", &block)
284
+ def to_xml(builder = nil, **opts, &block)
285
285
  if builder
286
- render_xml builder, root, &block
286
+ render_xml builder, **opts, &block
287
287
  else
288
288
  Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
289
- render_xml xml, root, &block
289
+ render_xml xml, **opts, &block
290
290
  end.doc.root.to_xml
291
291
  end
292
292
  end
@@ -298,15 +298,15 @@ module RelatonBib
298
298
 
299
299
  # @param builder [Nokogiri::XML::Builder]
300
300
  # @return [String]
301
- def render_xml(builder, root)
302
- xml = builder.send(root) do
301
+ def render_xml(builder, **opts)
302
+ xml = builder.send(opts.fetch :root, :bibitem) do
303
303
  builder.fetched fetched if fetched
304
304
  title.each { |t| builder.title { t.to_xml builder } }
305
305
  formattedref.to_xml builder if formattedref
306
306
  link.each { |s| s.to_xml builder }
307
307
  docidentifier.each { |di| di.to_xml builder }
308
308
  builder.docnumber docnumber if docnumber
309
- dates.each { |d| d.to_xml builder, full_date: true }
309
+ dates.each { |d| d.to_xml builder, **opts }
310
310
  contributors.each do |c|
311
311
  builder.contributor do
312
312
  c.role.each { |r| r.to_xml builder }
@@ -321,7 +321,7 @@ module RelatonBib
321
321
  abstract.each { |a| builder.abstract { a.to_xml(builder) } }
322
322
  status.to_xml builder if status
323
323
  copyright.to_xml builder if copyright
324
- relations.each { |r| r.to_xml builder }
324
+ relations.each { |r| r.to_xml builder, **opts }
325
325
  series.each { |s| s.to_xml builder } if series
326
326
  medium.to_xml builder if medium
327
327
  place.each { |pl| builder.place pl }
@@ -35,4 +35,4 @@ module RelatonBib
35
35
  end
36
36
  end
37
37
  end
38
- end
38
+ end
@@ -37,9 +37,9 @@ module RelatonBib
37
37
  end
38
38
 
39
39
  # @param builder [Nokogiri::XML::Builder]
40
- def to_xml(builder)
40
+ def to_xml(builder, **opts)
41
41
  builder.relation(type: type) do
42
- bibitem.to_xml(builder)
42
+ bibitem.to_xml(builder, **opts)
43
43
  bib_locality.each do |l|
44
44
  l.to_xml builder
45
45
  end
@@ -1,3 +1,5 @@
1
+ require "addressable"
2
+
1
3
  module RelatonBib
2
4
  # Typed URI
3
5
  class TypedUri
@@ -10,7 +12,7 @@ module RelatonBib
10
12
  # @param content [String]
11
13
  def initialize(type:, content:)
12
14
  @type = type
13
- @content = URI content if content
15
+ @content = Addressable::URI.parse content if content
14
16
  end
15
17
 
16
18
  def to_xml(builder)
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "0.1.2".freeze
2
+ VERSION = "0.1.3".freeze
3
3
  end
@@ -30,5 +30,6 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "ruby-debug-ide"
31
31
  spec.add_development_dependency "simplecov"
32
32
 
33
+ spec.add_dependency "addressable"
33
34
  spec.add_dependency "nokogiri", "~> 1.8.4"
34
35
  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.1.2
4
+ version: 0.1.3
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-05-08 00:00:00.000000000 Z
11
+ date: 2019-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: addressable
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: nokogiri
113
127
  requirement: !ruby/object:Gem::Requirement