relaton-bib 1.11.0 → 1.11.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
  SHA256:
3
- metadata.gz: a787155aa8128f6bbd98734d80eb23d60d890f564b0357b3d79070659a1322eb
4
- data.tar.gz: 92f839bcc00d8346aece24347903e833268d6c89df5da8150e108f680ae171fa
3
+ metadata.gz: 2fff6fdcb77f7545cc6989fa6dcc65eadfde4609ee167eaacf2648205a43a9d4
4
+ data.tar.gz: d2529ceddabe29e386900bceedc3f101e9bf441a87c5d9ac128a7450813083d2
5
5
  SHA512:
6
- metadata.gz: f9a7e7163e3d93cea465b269aea55a18e585fa65165512cfa383f05a081605c66680912d77b0a4878ff27690713cee8d8b28dc9bbb84bb2477cf854a799e1a23
7
- data.tar.gz: 017ea5aab785898a8ed574bc685a14006b2b60c936996a97b5b96e18746f1ac23d1dc43ebfd5886cec7416469e0a8843886277f8d4e5e4ade1cd907739318a2e
6
+ metadata.gz: d4aab0bed22dcc71b722547965dedc1a3b315cb092e5b08817cd760c2f3db4363d82d079d58da165f634f440974e2f474255a64a626c2917199ac546b3d05dc9
7
+ data.tar.gz: 21e8feee74c3f8c28b465068700b43c63f9f2ed81cca87974807cae646ed287def53651dce58c5fb5ca2ab274cf482cc1f34b634bdb276a39250df91ed000a6d
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.0".freeze
2
+ VERSION = "1.11.3".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
 
@@ -401,21 +420,25 @@ module RelatonBib
401
420
  def localities(rel)
402
421
  rel.xpath("./locality|./localityStack").map do |lc|
403
422
  if lc.name == "locality"
404
- Locality.new lc[:type], lc.at("referenceFrom").text, lc.at("referenceTo")&.text
423
+ locality lc
405
424
  else
406
425
  LocalityStack.new(lc.xpath("./locality").map { |l| locality l })
407
426
  end
408
427
  end
409
428
  end
410
429
 
430
+ #
431
+ # Create Locality object from Nokogiri::XML::Element
432
+ #
411
433
  # @param loc [Nokogiri::XML::Element]
434
+ # @param klass [RelatonBib::Locality.class, RelatonBib::LocalityStack.class]
435
+ #
412
436
  # @return [RelatonBib::Locality]
413
437
  def locality(loc, klass = Locality)
414
- ref_to = (rt = loc.at("./referenceTo")) && LocalizedString.new(rt.text)
415
438
  klass.new(
416
439
  loc[:type],
417
- LocalizedString.new(loc.at("./referenceFrom").text),
418
- ref_to,
440
+ loc.at("./referenceFrom")&.text,
441
+ loc.at("./referenceTo")&.text,
419
442
  )
420
443
  end
421
444
 
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.0
4
+ version: 1.11.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: 2022-04-10 00:00:00.000000000 Z
11
+ date: 2022-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug