relaton-bib 1.11.1 → 1.11.4

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: a2a973e714b86a5a78367ea697af8ba3eaa2861e571e3b035ec6ff411febc121
4
- data.tar.gz: dabc25e318c346add35e69e383fa00762c5589e684983d708785a00d48a5d60e
3
+ metadata.gz: 66d703af6f525fba6b4cd25e054ab2f5f64e0d5040b75430c04296990a6a12ca
4
+ data.tar.gz: c0c85e99f1e3b511fbc329b9b631349ed63afee1a1779a2147a1756e6dbf0559
5
5
  SHA512:
6
- metadata.gz: 6690ae53c5056fd830923eb85b5c04f1b652a5bb46c7024ae9f5ecf6f97cebd1d58d57a8069191b349dae9f50a050abdc8eb78375baa7e2f3e23ac1a8ec6290a
7
- data.tar.gz: a8fa5e09f9630117c05e3594796f5eb04a8f54c7af344a709a264c8e9be45ce951ec1fc9f25b971193d64e824368babef489c29509bd2356a4c627d8ac384c47
6
+ metadata.gz: d8f4ef1047ad4d3ab345c3d67079ca66e986b707871f243c11eb8c52ba5792202bf046bbcb1b3722d957d3e882e3ce645b30d9f5a422a8f8ccd2ac38eb7a7d12
7
+ data.tar.gz: 2974513d8a823bc2efbbfe51e4bc9a88c7e7f77b3aa117e2835b5e13d6b33f366b0c15e7987afcb2dc1b5f5aa9f63d5a45e0df384ffb321132df30d2ed6ebe09
@@ -16,7 +16,7 @@ jobs:
16
16
  strategy:
17
17
  fail-fast: false
18
18
  matrix:
19
- ruby: [ '3.0', '2.7', '2.6', '2.5' ]
19
+ ruby: [ '3.0', '2.7', '2.6' ]
20
20
  os: [ ubuntu-latest, windows-latest, macos-latest ]
21
21
  experimental: [ false ]
22
22
  steps:
@@ -24,10 +24,6 @@ jobs:
24
24
  with:
25
25
  submodules: true
26
26
 
27
- # https://github.com/ruby-debug/debase/issues/89#issuecomment-686827382
28
- - if: matrix.os == 'macos-latest' && matrix.ruby == '2.5'
29
- run: echo BUNDLE_BUILD__DEBASE="--with-cflags=\"-Wno-error=implicit-function-declaration\"" >> $GITHUB_ENV
30
-
31
27
  - uses: ruby/setup-ruby@v1
32
28
  with:
33
29
  ruby-version: ${{ matrix.ruby }}
data/README.adoc CHANGED
@@ -213,7 +213,11 @@ item = RelatonBib::BibliographicItem.new(
213
213
  ),
214
214
  place: [
215
215
  "bib place",
216
- RelatonBib::Place.new(name: "Geneva", uri: "geneva.place", region: "Switzelznd")
216
+ RelatonBib::Place.new(
217
+ city: "Geneva",
218
+ region: [RelatonBib::Place::RegionType.new(name: "Region")],
219
+ country: [RelatonBib::Place::RegionType.new(name: "Switzeland", iso: "SH", recommended: true)],
220
+ )
217
221
  ],
218
222
  extent: [
219
223
  RelatonBib::BibItemLocality.new("section", "Reference from", "Reference to"),
@@ -412,6 +416,19 @@ item.to_bibtex
412
416
  ...
413
417
  ----
414
418
 
419
+ === Export bibliographic item to Citeproc
420
+
421
+ [source,ruby]
422
+ ----
423
+ item.to_citeproc
424
+ => [{"title"=>"Geographic information",
425
+ "edition"=>"1",
426
+ "author"=>[{"family"=>"Bierman", "given"=>"A."}, {"family"=>"Bierman", "given"=>"Forename"}],
427
+ "publisher"=>"Institute of Electrical and Electronics Engineers",
428
+ "publisher-place"=>"bib place",
429
+ ...
430
+ ----
431
+
415
432
  === Exporting bibliographic item to AsciiBib
416
433
 
417
434
  [source,ruby]
data/grammars/biblio.rng CHANGED
@@ -527,7 +527,7 @@
527
527
  </define>
528
528
  <define name="LocalityType">
529
529
  <data type="string">
530
- <param name="pattern">section|clause|part|paragraph|chapter|page|whole|table|annex|figure|note|list|example|volume|issue|time|anchor|locality:[a-zA-Z0-9_]+</param>
530
+ <param name="pattern">section|clause|part|paragraph|chapter|page|title|line|whole|table|annex|figure|note|list|example|volume|issue|time|anchor|locality:[a-zA-Z0-9_]+</param>
531
531
  </data>
532
532
  </define>
533
533
  <define name="referenceFrom">
@@ -851,17 +851,46 @@
851
851
  </define>
852
852
  <define name="bplace">
853
853
  <element name="place">
854
- <optional>
855
- <attribute name="uri">
856
- <data type="anyURI"/>
857
- </attribute>
858
- </optional>
859
- <optional>
860
- <attribute name="region"/>
861
- </optional>
854
+ <choice>
855
+ <text/>
856
+ <group>
857
+ <ref name="bibliocity"/>
858
+ <zeroOrMore>
859
+ <ref name="biblioregion"/>
860
+ </zeroOrMore>
861
+ <zeroOrMore>
862
+ <ref name="bibliocountry"/>
863
+ </zeroOrMore>
864
+ </group>
865
+ </choice>
866
+ </element>
867
+ </define>
868
+ <define name="bibliocity">
869
+ <element name="city">
862
870
  <text/>
863
871
  </element>
864
872
  </define>
873
+ <define name="biblioregion">
874
+ <element name="region">
875
+ <ref name="RegionType"/>
876
+ </element>
877
+ </define>
878
+ <define name="bibliocountry">
879
+ <element name="country">
880
+ <ref name="RegionType"/>
881
+ </element>
882
+ </define>
883
+ <define name="RegionType">
884
+ <optional>
885
+ <attribute name="iso"/>
886
+ </optional>
887
+ <optional>
888
+ <attribute name="recommended">
889
+ <data type="boolean"/>
890
+ </attribute>
891
+ </optional>
892
+ <text/>
893
+ </define>
865
894
  <define name="bprice">
866
895
  <element name="price">
867
896
  <attribute name="currency"/>
@@ -401,30 +401,26 @@ module RelatonBib
401
401
  hash
402
402
  end
403
403
 
404
- # @param bibtex [BibTeX::Bibliography, NilClass]
404
+ #
405
+ # Reander BibTeX
406
+ #
407
+ # @param bibtex [BibTeX::Bibliography, nil]
408
+ #
405
409
  # @return [String]
406
- def to_bibtex(bibtex = nil) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
407
- item = BibTeX::Entry.new
408
- item.type = bibtex_type
409
- item.key = id
410
- bibtex_title item
411
- item.edition = edition if edition
412
- bibtex_author item
413
- bibtex_contributor item
414
- item.address = place.first.name if place.any?
415
- bibtex_note item
416
- bibtex_relation item
417
- bibtex_extent item
418
- bibtex_date item
419
- bibtex_series item
420
- bibtex_classification item
421
- item.keywords = keyword.map(&:content).join(", ") if keyword.any?
422
- bibtex_docidentifier item
423
- item.timestamp = fetched.to_s if fetched
424
- bibtex_link item
425
- bibtex ||= BibTeX::Bibliography.new
426
- bibtex << item
427
- bibtex.to_s
410
+ #
411
+ def to_bibtex(bibtex = nil)
412
+ bibtext_item(bibtex).to_s
413
+ end
414
+
415
+ #
416
+ # Render citeproc
417
+ #
418
+ # @param bibtex [BibTeX::Bibliography, nil]
419
+ #
420
+ # @return [Hash] citeproc
421
+ #
422
+ def to_citeproc(bibtex = nil)
423
+ bibtext_item(bibtex).to_citeproc.map { |cp| cp.transform_keys(&:to_s) }
428
424
  end
429
425
 
430
426
  # @param lang [String, nil] language code Iso639
@@ -555,13 +551,35 @@ module RelatonBib
555
551
 
556
552
  private
557
553
 
558
- # @return [String]
559
- def bibtex_title(item)
560
- title.each do |t|
561
- case t.type
562
- when "main" then item.tile = t.title.content
563
- end
564
- end
554
+ #
555
+ # Create BibTeX item for this document
556
+ #
557
+ # @param [BibTeX::Bibliography, nil] bibtex <description>
558
+ #
559
+ # @return [BibTeX::Bibliography] BibTeX bibliography
560
+ #
561
+ def bibtext_item(bibtex) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
562
+ item = BibTeX::Entry.new
563
+ item.type = bibtex_type
564
+ item.key = id
565
+ title.to_bibtex item
566
+ item.edition = edition if edition
567
+ bibtex_author item
568
+ bibtex_contributor item
569
+ item.address = place.first.name if place.any?
570
+ bibtex_note item
571
+ bibtex_relation item
572
+ bibtex_extent item
573
+ bibtex_date item
574
+ bibtex_series item
575
+ bibtex_classification item
576
+ item.keywords = keyword.map(&:content).join(", ") if keyword.any?
577
+ bibtex_docidentifier item
578
+ item.timestamp = fetched.to_s if fetched
579
+ bibtex_link item
580
+ bibtex ||= BibTeX::Bibliography.new
581
+ bibtex << item
582
+ bibtex
565
583
  end
566
584
 
567
585
  # @return [String]
@@ -1,49 +1,141 @@
1
1
  module RelatonBib
2
2
  class Place
3
- # @return [String]
4
- attr_reader :name
5
-
6
- # @return [String, NilClass]
7
- attr_reader :uri, :region
8
-
9
- # @param name [String]
10
- # @param uri [String, NilClass]
11
- # @param region [String, NilClass]
12
- def initialize(name:, uri: nil, region: nil)
13
- @name = name
14
- @uri = uri
15
- @region = region
3
+ # @return [String, nil]
4
+ attr_reader :name, :city
5
+
6
+ # @return [Array<RelatonBib::Place::RegionType>]
7
+ attr_reader :region, :country
8
+
9
+ #
10
+ # Initialize place.
11
+ #
12
+ # @param name [String, nil] name of place, name or city should be provided
13
+ # @param city [String, nil] name of city, city or name should be provided
14
+ # @param region [Array<RelatonBib::Place::RegionType>] region of place
15
+ # @param country [Array<RelatonBib::Place::RegionType>] country of place
16
+ #
17
+ def initialize(name: nil, city: nil, region: [], country: []) # rubocop:disable Metrics/CyclomaticComplexity
18
+ if name.nil? && city.nil?
19
+ raise ArgumentError, "`name` or `city` should be provided"
20
+ end
21
+
22
+ @name = name
23
+ @city = city
24
+ @region = region.map { |r| r.is_a?(Hash) ? RegionType.new(**r) : r }
25
+ @country = country.map { |c| c.is_a?(Hash) ? RegionType.new(**c) : c }
16
26
  end
17
27
 
28
+ #
29
+ # Render place as XML.
30
+ #
18
31
  # @param builder [Nologiri::XML::Builder]
32
+ #
19
33
  def to_xml(builder)
20
- xml = builder.place name
21
- xml[:uri] = uri if uri
22
- xml[:region] = region if region
34
+ if name
35
+ builder.place name
36
+ else
37
+ builder.place do |b|
38
+ b.city city
39
+ region.each { |r| b.region { r.to_xml b } }
40
+ country.each { |c| b.country { c.to_xml b } }
41
+ end
42
+ end
23
43
  end
24
44
 
45
+ #
46
+ # Render place as Hash.
47
+ #
25
48
  # @return [Hash]
49
+ #
26
50
  def to_hash
27
- if uri || region
28
- hash = { "name" => name }
29
- hash["uri"] = uri if uri
30
- hash["region"] = region if region
31
- hash
51
+ if name then name
32
52
  else
33
- name
53
+ hash = { "city" => city }
54
+ hash["region"] = region.map(&:to_hash) if region.any?
55
+ hash["country"] = country.map(&:to_hash) if country.any?
56
+ hash
34
57
  end
35
58
  end
36
59
 
60
+ #
61
+ # Render place as AsciiBib.
62
+ #
37
63
  # @param prefix [String]
38
64
  # @param count [Integer] number of places
65
+ #
39
66
  # @return [Stirng]
40
- def to_asciibib(prefix = "", count = 1)
41
- pref = prefix.empty? ? "place" : prefix + ".place"
67
+ #
68
+ def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize
69
+ pref = prefix.empty? ? "place" : "#{prefix}.place"
42
70
  out = count > 1 ? "#{pref}::\n" : ""
43
- out += "#{pref}.name:: #{name}\n"
44
- out += "#{pref}.uri:: #{uri}\n" if uri
45
- out += "#{pref}.region:: #{region}\n" if region
46
- out
71
+ return "#{out}#{pref}.name:: #{name}\n" if name
72
+
73
+ out += "#{pref}.city:: #{city}\n"
74
+ out += region.map { |r| r.to_asciibib("#{pref}.region", region.size) }.join
75
+ out + country.map { |c| c.to_asciibib("#{pref}.country", country.size) }.join
76
+ end
77
+
78
+ class RegionType
79
+ # @return [Strign] name of region
80
+ attr_reader :name
81
+
82
+ # @return [Strign, nil] ISO code of region
83
+ attr_reader :iso
84
+
85
+ # @return [Boolean, nil] <description>
86
+ attr_reader :recommended
87
+
88
+ #
89
+ # Initialize region type.
90
+ #
91
+ # @param [String] name name of region
92
+ # @param [String, nil] iso ISO code of region
93
+ # @param [Boolean, nil] recommended recommended region
94
+ #
95
+ def initialize(name:, iso: nil, recommended: nil)
96
+ @name = name
97
+ @iso = iso
98
+ @recommended = recommended
99
+ end
100
+
101
+ #
102
+ # Render region type as XML.
103
+ #
104
+ # @param [Nokogiri::XML::Builder] builder XML builder
105
+ #
106
+ def to_xml(builder)
107
+ builder.parent["iso"] = iso if iso
108
+ builder.parent["recommended"] = recommended.to_s unless recommended.nil?
109
+ builder.text name
110
+ end
111
+
112
+ #
113
+ # Render region type as Hash.
114
+ #
115
+ # @return [Hash] region type as Hash
116
+ #
117
+ def to_hash
118
+ hash = { "name" => name }
119
+ hash["iso"] = iso if iso
120
+ hash["recommended"] = recommended unless recommended.nil?
121
+ hash
122
+ end
123
+
124
+ #
125
+ # Render region type as AsciiBib.
126
+ #
127
+ # @param [String] pref prefix
128
+ # @param [Integer] count number of region types
129
+ #
130
+ # @return [String] region type as AsciiBib
131
+ #
132
+ def to_asciibib(pref, count = 1) # rubocop:disable Metrics/AbcSize
133
+ out = count > 1 ? "#{pref}::\n" : ""
134
+ out += "#{pref}.name:: #{name}\n"
135
+ out += "#{pref}.iso:: #{iso}\n" if iso
136
+ out += "#{pref}.recommended:: #{recommended}\n" if recommended
137
+ out
138
+ end
47
139
  end
48
140
  end
49
141
  end
@@ -62,6 +62,18 @@ module RelatonBib
62
62
  tl.each { |t| opts[:builder].title { t.to_xml opts[:builder] } }
63
63
  end
64
64
 
65
+ #
66
+ # Add main title ot bibtex entry
67
+ #
68
+ # @param [BibTeX::Entry] item bibtex entry
69
+ #
70
+ def to_bibtex(item)
71
+ tl = titles.detect { |t| t.type == "main" }
72
+ return unless tl
73
+
74
+ item.title = tl.title.content
75
+ end
76
+
65
77
  private
66
78
 
67
79
  # @param lang [String]
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.11.1".freeze
2
+ VERSION = "1.11.4".freeze
3
3
  end
@@ -72,7 +72,26 @@ module RelatonBib
72
72
 
73
73
  def fetch_place(item)
74
74
  item.xpath("./place").map do |pl|
75
- Place.new(name: pl.text, uri: pl[:uri], region: pl[:region])
75
+ if (city = pl.at("./city"))
76
+ Place.new(city: city.text, region: create_region_country(pl),
77
+ country: create_region_country(pl, "country"))
78
+ else
79
+ Place.new(name: pl.text)
80
+ end
81
+ end
82
+ end
83
+
84
+ #
85
+ # Create region or country from place element
86
+ #
87
+ # @param [Nokogiri::XML::Element] place place element
88
+ # @param [String] node name of the node to parse
89
+ #
90
+ # @return [Array<RelatonBib::Place::RegionType>] <description>
91
+ #
92
+ def create_region_country(place, node = "region")
93
+ place.xpath("./#{node}").map do |r|
94
+ Place::RegionType.new(name: r.text, iso: r[:iso], recommended: r[:recommended])
76
95
  end
77
96
  end
78
97
 
data/relaton-bib.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.bindir = "exe"
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
- spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
24
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
25
25
 
26
26
  spec.add_development_dependency "byebug"
27
27
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
@@ -36,5 +36,5 @@ Gem::Specification.new do |spec|
36
36
  spec.add_dependency "addressable"
37
37
  spec.add_dependency "bibtex-ruby"
38
38
  spec.add_dependency "iso639"
39
- spec.add_dependency "nokogiri", "~> 1.12.5"
39
+ spec.add_dependency "nokogiri", "~> 1.13.0"
40
40
  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: 1.11.1
4
+ version: 1.11.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-11 00:00:00.000000000 Z
11
+ date: 2022-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -184,14 +184,14 @@ dependencies:
184
184
  requirements:
185
185
  - - "~>"
186
186
  - !ruby/object:Gem::Version
187
- version: 1.12.5
187
+ version: 1.13.0
188
188
  type: :runtime
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - "~>"
193
193
  - !ruby/object:Gem::Version
194
- version: 1.12.5
194
+ version: 1.13.0
195
195
  description: 'RelatonBib: Ruby XMLDOC impementation.'
196
196
  email:
197
197
  - open.source@ribose.com
@@ -270,7 +270,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
270
270
  requirements:
271
271
  - - ">="
272
272
  - !ruby/object:Gem::Version
273
- version: 2.5.0
273
+ version: 2.6.0
274
274
  required_rubygems_version: !ruby/object:Gem::Requirement
275
275
  requirements:
276
276
  - - ">="