relaton-bib 0.5.2 → 0.6.0

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
  SHA256:
3
- metadata.gz: 5dd4730cb860ea6fea05b214a89a7e180acca7cebdfde515924cff5cbc006631
4
- data.tar.gz: c71b46fefb288fdc2b3e51122d793cd225431bd5818aad704bbf78dfc8aa36c0
3
+ metadata.gz: 8ef89450c5deeab8305d50a98218ad8c6b8425904cfdc8918542fed5ee2790e5
4
+ data.tar.gz: 60dccc2abedbb9f0bc940552d363c67d65b9c31c4bff4bde2d7e99ef3bc9a9a5
5
5
  SHA512:
6
- metadata.gz: 22616fba5d4a2a502b2f969efacb00a8384e94d69b75147687ea0f086019d1614db7e5393c6b4d2e7ea5eb336332c5a208690ddda0bdd1593ed29b344a48d049
7
- data.tar.gz: f2d074312be6ed3194b08dc0b6e5cc2eb6b269216d1b0500b072fb6868b66e47d09fa21abfc5dd43cf2e22fdb82fd948c0597526fec64da5c8ee2e8dc4ae6c85
6
+ metadata.gz: b5015108cf9f8e97cd39de74eb6db49886aafd43beb048c7a0dadd1013a5de31b565cd6bdd400cfcf068de4b421e593007962cfafbf82262e6f30a7a156e8fc8
7
+ data.tar.gz: 1bc31977d22338c4491d1b45472746dec975e7b4ead6732437b6e206cb3f52e17ba8070a20ff84fd8cc7b6c69d5d2a4958ce4e1be958bb4ec4ab84495daddf5e
@@ -113,6 +113,9 @@ module RelatonBib
113
113
  # @return [Date]
114
114
  attr_reader :fetched
115
115
 
116
+ # @return [Array<RelatonBib::LocalizedString>]
117
+ attr_reader :keyword
118
+
116
119
  # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
117
120
  # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
118
121
 
@@ -136,6 +139,7 @@ module RelatonBib
136
139
  # @param classification [Array<RelatonBib::Classification>]
137
140
  # @param validity [RelatonBib:Validity, NilClass]
138
141
  # @param fetched [Date, NilClass] default nil
142
+ # @param keyword [Array<String>]
139
143
  #
140
144
  # @param copyright [Hash, RelatonBib::CopyrightAssociation, NilClass]
141
145
  # @option copyright [Hash, RelatonBib::ContributionInfo] :owner
@@ -222,6 +226,7 @@ module RelatonBib
222
226
  @classification = args.fetch :classification, []
223
227
  @validity = args[:validity]
224
228
  @fetched = args.fetch :fetched, nil # , Date.today # we should pass the fetched arg from scrappers
229
+ @keyword = (args[:keyword] || []).map { |kw| LocalizedString.new(kw) }
225
230
  end
226
231
  # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
227
232
  # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
@@ -303,6 +308,7 @@ module RelatonBib
303
308
  hash["classification"] = single_element_array(classification) if classification&.any?
304
309
  hash["validity"] = validity.to_hash if validity
305
310
  hash["fetched"] = fetched.to_s if fetched
311
+ hash["keyword"] = single_element_array(keyword) if keyword&.any?
306
312
  hash
307
313
  end
308
314
 
@@ -323,6 +329,7 @@ module RelatonBib
323
329
  bibtex_date item
324
330
  bibtex_series item
325
331
  bibtex_classification item
332
+ item.keywords = keyword.map(&:content).join(", ") if keyword.any?
326
333
  bibtex_docidentifier item
327
334
  item.timestamp = fetched.to_s if fetched
328
335
  bibtex_link item
@@ -455,7 +462,7 @@ module RelatonBib
455
462
  classification.each do |c|
456
463
  case c.type
457
464
  when "type" then item["type"] = c.value
458
- when "keyword" then item.keywords = c.value
465
+ # when "keyword" then item.keywords = c.value
459
466
  when "mendeley" then item["mendeley-tags"] = c.value
460
467
  end
461
468
  end
@@ -520,6 +527,7 @@ module RelatonBib
520
527
  extent.each { |e| builder.extent { e.to_xml builder } }
521
528
  accesslocation.each { |al| builder.accesslocation al }
522
529
  classification.each { |cls| cls.to_xml builder }
530
+ keyword.each { |kw| builder.keyword { kw.to_xml(builder) } }
523
531
  validity&.to_xml builder
524
532
  if block_given?
525
533
  yield builder
@@ -24,7 +24,8 @@ module RelatonBib
24
24
  series: fetch_series(bt),
25
25
  link: fetch_link(bt),
26
26
  language: fetch_language(bt),
27
- classification: fetch_classification(bt)
27
+ classification: fetch_classification(bt),
28
+ keyword: fetch_keyword(bt)
28
29
  )
29
30
  h
30
31
  end
@@ -225,12 +226,18 @@ module RelatonBib
225
226
  def fetch_classification(bibtex)
226
227
  cls = []
227
228
  cls << Classification.new(type: "type", value: bibtex["type"].to_s) if bibtex["type"]
228
- cls << Classification.new(type: "keyword", value: bibtex.keywords.to_s) if bibtex["keywords"]
229
+ # cls << Classification.new(type: "keyword", value: bibtex.keywords.to_s) if bibtex["keywords"]
229
230
  if bibtex["mendeley-tags"]
230
- cls << Classification.new(type: "mendeley", value: bibtex["mendeley-tags"].to_s)
231
+ cls << Classification.new(type: "mendeley", value: bibtex["mendeley-tags"].to_s)
231
232
  end
232
233
  cls
233
234
  end
235
+
236
+ # @param bibtex [BibTeX::Entry]
237
+ # @return [Array<String>]
238
+ def fetch_keyword(bibtex)
239
+ bibtex["keywords"]&.split(", ") || []
240
+ end
234
241
  end
235
242
  end
236
243
  end
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "0.5.2".freeze
2
+ VERSION = "0.6.0".freeze
3
3
  end
@@ -42,6 +42,7 @@ module RelatonBib
42
42
  extent: fetch_extent(bibitem),
43
43
  accesslocation: bibitem.xpath("./accesslocation").map(&:text),
44
44
  classification: fetch_classification(bibitem),
45
+ keyword: fetch_keyword(bibitem),
45
46
  validity: fetch_validity(bibitem),
46
47
  }
47
48
  end
@@ -124,6 +125,10 @@ module RelatonBib
124
125
  end
125
126
  end
126
127
 
128
+ def fetch_keyword(item)
129
+ item.xpath("keyword").map &:text
130
+ end
131
+
127
132
  def fetch_validity(item)
128
133
  vl = item.at("./validity")
129
134
  return unless vl
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.5.2
4
+ version: 0.6.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-02-12 00:00:00.000000000 Z
11
+ date: 2020-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: debase
@@ -218,7 +218,6 @@ files:
218
218
  - lib/relaton_bib/formatted_ref.rb
219
219
  - lib/relaton_bib/formatted_string.rb
220
220
  - lib/relaton_bib/hash_converter.rb
221
- - lib/relaton_bib/hash_to_bib.rb
222
221
  - lib/relaton_bib/hit.rb
223
222
  - lib/relaton_bib/hit_collection.rb
224
223
  - lib/relaton_bib/localized_string.rb
@@ -1,70 +0,0 @@
1
- module RelatonBib
2
- class << self
3
- def hash_to_bib(args, nested = false)
4
- return nil unless args.is_a?(Hash)
5
- ret = Marshal.load(Marshal.dump(symbolize(args))) # deep copy
6
- timestamp_hash(ret) unless nested
7
- title_hash_to_bib(ret)
8
- link_hash_to_bib(ret)
9
- language_hash_to_bib(ret)
10
- script_hash_to_bib(ret)
11
- dates_hash_to_bib(ret)
12
- docid_hash_to_bib(ret)
13
- version_hash_to_bib(ret)
14
- biblionote_hash_to_bib(ret)
15
- abstract_hash_to_bib(ret)
16
- formattedref_hash_to_bib(ret)
17
- docstatus_hash_to_bib(ret)
18
- contributors_hash_to_bib(ret)
19
- relations_hash_to_bib(ret)
20
- series_hash_to_bib(ret)
21
- medium_hash_to_bib(ret)
22
- place_hash_to_bib(ret)
23
- extent_hash_to_bib(ret)
24
- accesslocation_hash_to_bib(ret)
25
- classification_hash_to_bib(ret)
26
- validity_hash_to_bib(ret)
27
- ret
28
- end
29
-
30
- def timestamp_hash(ret)
31
- ret[:fetched] ||= Date.today.to_s
32
- end
33
-
34
- def symbolize(obj)
35
- obj.is_a? Hash and
36
- return obj.inject({}){|memo,(k,v)| memo[k.to_sym] = symbolize(v); memo}
37
- obj.is_a? Array and
38
- return obj.inject([]){|memo,v | memo << symbolize(v); memo}
39
- return obj
40
- end
41
-
42
- def array(a)
43
- return [] unless a
44
- return [].push(a) unless a.is_a?(Array)
45
- a
46
- end
47
-
48
- def localname(f, c)
49
- return nil if f.nil?
50
- f.is_a?(Hash) and lang = f[:language]
51
- lang ||= c[:name][:language]
52
- f.is_a?(Hash) and script = f[:script]
53
- script ||= c[:name][:script]
54
- f.is_a?(Hash) ?
55
- RelatonBib::LocalizedString.new(f[:content], lang, script) :
56
- RelatonBib::LocalizedString.new(f, lang, script)
57
- end
58
-
59
- def localizedstring(f)
60
- f.is_a?(Hash) ?
61
- RelatonBib::LocalizedString.new(f[:content], f[:language], f[:script]) :
62
- RelatonBib::LocalizedString.new(f)
63
- end
64
-
65
- def formattedref(f)
66
- f.is_a?(Hash) ? RelatonBib::FormattedRef.new(f) :
67
- RelatonBib::FormattedRef.new(content: f)
68
- end
69
- end
70
- end