relaton-gb 0.6.0 → 0.6.1

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: 87629d5d68e9798b8e251cdfd3c5248676cc93dd
4
- data.tar.gz: 94c3a025a0db145fb4433fe12259cd8001ffdd9c
3
+ metadata.gz: '08660ea6761c9bcf3be4f3876838dc33b19bf25d'
4
+ data.tar.gz: '02690d3dd1ee0c0396a86a9e3e360ffd52468822'
5
5
  SHA512:
6
- metadata.gz: 553214749bbd2b4ba9e046f7e4a3d36201a219bb90c865ea42c2d09c995f7291281a249812a589984a8a713b8a2996d1819a911e96618534debf468c10040667
7
- data.tar.gz: 2282a0d505cdd6a7499d0ab5e9ae91e8a1bbf8b2ab0ab8342331b14e9cb9d13a5d6b34bf4a7af76cfd861abfe2c63b489951329eec728aae92610bfc8bc70a51
6
+ metadata.gz: 23d003d2e3cdb41c3f3fc573dac0258c74eaaa00a4cc096f5eef3354f8538a19ddc72cab102bc60a61991ac66c8f2e2739e7ac742ade485835b9dc19cb0465bf
7
+ data.tar.gz: 86d5166d5e78449170184e9673fed3be8b7900832362279d2bc55d3b0e2596bad1e9e0286da64eb7a77069355f92bca5e37a5493aa87155ce9dfda263993fdb3
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- relaton-gb (0.6.0)
4
+ relaton-gb (0.6.1)
5
5
  cnccs (~> 0.1.1)
6
6
  gb-agencies (~> 0.0.1)
7
7
  relaton-iso-bib (~> 0.3.0)
@@ -36,10 +36,10 @@ GEM
36
36
  pry (~> 0.10)
37
37
  public_suffix (3.1.1)
38
38
  rake (10.5.0)
39
- relaton-bib (0.3.0)
39
+ relaton-bib (0.3.2)
40
40
  addressable
41
41
  nokogiri (~> 1.10)
42
- relaton-iso-bib (0.3.0)
42
+ relaton-iso-bib (0.3.2)
43
43
  isoics (~> 0.1.6)
44
44
  relaton-bib (~> 0.3.0)
45
45
  ruby_deep_clone (~> 0.8.0)
@@ -108,6 +108,21 @@ hit_collection.first.fetch.date
108
108
  => [#<RelatonBib::BibliographicDate:0x007f975a0207d0 @from=nil, @on=2006-03-10 00:00:00 +0100, @to=nil, @type="published">]
109
109
  ----
110
110
 
111
+ === Create bibliographic item form YAML
112
+ [source,ruby]
113
+ ----
114
+ hash = YAML.load_file 'spec/examples/gb_bib_item.yml'
115
+ => {"id"=>"JB/T13368",
116
+ ...
117
+
118
+ bib_hash = RelatonGb::HashConverter.hash_to_bib hash
119
+ => {:id=>"JB/T13368",
120
+ ...
121
+
122
+ RelatonGb::GbBibliographicItem.new bib_hash
123
+ => <RelatonGb::GbBibliographicItem:0x007fc680802700>
124
+ ----
125
+
111
126
  === Serialization
112
127
 
113
128
  [source,ruby]
@@ -5,6 +5,7 @@ require "cnccs"
5
5
  require "relaton_gb/gb_technical_committee"
6
6
  require "relaton_gb/gb_standard_type"
7
7
  require "relaton_gb/xml_parser"
8
+ require "relaton_gb/hash_converter"
8
9
 
9
10
  module RelatonGb
10
11
  # GB bibliographic item class.
@@ -30,7 +31,7 @@ module RelatonGb
30
31
  def initialize(**args)
31
32
  super
32
33
  args[:committee] && @committee = GbTechnicalCommittee.new(args[:committee])
33
- @ccs = args[:ccs].map { |c| Cnccs.fetch c }
34
+ @ccs = args[:ccs].map { |c| c.is_a?(Cnccs::Ccs) ? c : Cnccs.fetch(c) }
34
35
  @gbtype = GbStandardType.new args[:gbtype]
35
36
  @type = args[:type]
36
37
  @gbplannumber = args[:gbplannumber] || structuredidentifier&.project_number
@@ -0,0 +1,45 @@
1
+ require "yaml"
2
+
3
+ module RelatonGb
4
+ class HashConverter < RelatonIsoBib::HashConverter
5
+ class << self
6
+ # @override RelatonBib::HashConverter.hash_to_bib
7
+ # @param args [Hash]
8
+ # @param nested [TrueClass, FalseClass]
9
+ # @return [Hash]
10
+ def hash_to_bib(args, nested = false)
11
+ ret = super
12
+ return if ret.nil?
13
+
14
+ committee_hash_to_bib(ret)
15
+ ccs_hash_to_bib(ret)
16
+ ret
17
+ end
18
+
19
+ private
20
+
21
+ def committee_hash_to_bib(ret)
22
+ return unless ret[:title]
23
+
24
+ ret[:title] = array(ret[:title])
25
+ ret[:title] = ret[:title].map do |t|
26
+ titleparts = {}
27
+ titleparts = split_title(t) unless t.is_a?(Hash)
28
+ if t.is_a?(Hash) && t[:content]
29
+ titleparts = split_title(t[:content], t[:language], t[:script])
30
+ end
31
+ if t.is_a?(Hash) then t.merge(titleparts)
32
+ else
33
+ { content: t, language: "en", script: "Latn", format: "text/plain", type: "main" }
34
+ end
35
+ end
36
+ end
37
+
38
+ def ccs_hash_to_bib(ret)
39
+ ret[:ccs] = ret.fetch(:ccs, []).map do |ccs|
40
+ ccs[:code] ? Cnccs.fetch(ccs[:code]) : Cnccs.fetch(ccs)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -73,7 +73,7 @@ module RelatonGb
73
73
  { language: "en", content: gb_en.standard_agency1(gbtype[:scope], name, gbtype[:mandate]) },
74
74
  { language: "zh", content: gb_zh.standard_agency1(gbtype[:scope], name, gbtype[:mandate]) },
75
75
  ]
76
- [{ entity: entity, role: ["publisher"] }]
76
+ [{ entity: entity, role: [type: "publisher"] }]
77
77
  end
78
78
 
79
79
  # @param doc [Nokogiri::HTML::Document]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelatonGb
4
- VERSION = "0.6.0"
4
+ VERSION = "0.6.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-gb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
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-07-24 00:00:00.000000000 Z
11
+ date: 2019-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -192,6 +192,7 @@ files:
192
192
  - lib/relaton_gb/gb_scrapper.rb
193
193
  - lib/relaton_gb/gb_standard_type.rb
194
194
  - lib/relaton_gb/gb_technical_committee.rb
195
+ - lib/relaton_gb/hash_converter.rb
195
196
  - lib/relaton_gb/hit.rb
196
197
  - lib/relaton_gb/hit_collection.rb
197
198
  - lib/relaton_gb/scrapper.rb