relaton-bib 1.20.8 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/.rubocop.yml +1 -1
- data/CLAUDE.md +96 -0
- data/Gemfile +1 -4
- data/README.adoc +195 -154
- data/bin/console +1 -1
- data/grammars/basicdoc.rng +1572 -671
- data/grammars/biblio-standoc.rng +107 -46
- data/grammars/biblio.rng +1012 -377
- data/grammars/versions.json +26 -26
- data/lib/relaton/bib/converter/asciibib/to_asciibib.rb +663 -0
- data/lib/relaton/bib/converter/asciibib.rb +13 -0
- data/lib/relaton/bib/converter/bibtex/from_bibtex.rb +245 -0
- data/lib/relaton/bib/converter/bibtex/to_bibtex.rb +341 -0
- data/lib/relaton/bib/converter/bibtex.rb +23 -0
- data/lib/relaton/bib/converter/bibxml/from_rfcxml.rb +383 -0
- data/lib/relaton/bib/converter/bibxml/from_rfcxml_referencegroup.rb +71 -0
- data/lib/relaton/bib/converter/bibxml/to_rfcxml.rb +305 -0
- data/lib/relaton/bib/converter/bibxml/to_rfcxml_referencegroup.rb +52 -0
- data/lib/relaton/bib/converter/bibxml.rb +51 -0
- data/lib/relaton/bib/hash_parser_v1.rb +754 -0
- data/lib/relaton/bib/item_data.rb +229 -0
- data/lib/relaton/bib/model/abstract.rb +16 -0
- data/lib/relaton/bib/model/address.rb +22 -0
- data/lib/relaton/bib/model/affiliation.rb +16 -0
- data/lib/relaton/bib/model/bibdata.rb +24 -0
- data/lib/relaton/bib/model/bibitem.rb +23 -0
- data/lib/relaton/bib/model/contact.rb +18 -0
- data/lib/relaton/bib/model/contribution_info.rb +16 -0
- data/lib/relaton/bib/model/contributor.rb +71 -0
- data/lib/relaton/bib/model/copyright.rb +27 -0
- data/lib/relaton/bib/model/date.rb +31 -0
- data/lib/relaton/bib/model/depiction.rb +16 -0
- data/lib/relaton/bib/model/docidentifier.rb +33 -0
- data/lib/relaton/bib/model/doctype.rb +14 -0
- data/lib/relaton/bib/model/edition.rb +14 -0
- data/lib/relaton/bib/model/ext.rb +26 -0
- data/lib/relaton/bib/model/extent.rb +16 -0
- data/lib/relaton/bib/model/formattedref.rb +43 -0
- data/lib/relaton/bib/model/full_name_type.rb +64 -0
- data/lib/relaton/bib/model/fullname.rb +11 -0
- data/lib/relaton/bib/model/ics.rb +23 -0
- data/lib/relaton/bib/model/image.rb +28 -0
- data/lib/relaton/bib/model/item.rb +137 -0
- data/lib/relaton/bib/model/item_base.rb +27 -0
- data/lib/relaton/bib/model/keyword.rb +30 -0
- data/lib/relaton/bib/model/locality.rb +18 -0
- data/lib/relaton/bib/model/locality_stack.rb +14 -0
- data/lib/relaton/bib/model/localized_string.rb +57 -0
- data/lib/relaton/bib/model/localized_string_attrs.rb +24 -0
- data/lib/relaton/bib/model/logo.rb +14 -0
- data/lib/relaton/bib/model/medium.rb +22 -0
- data/lib/relaton/bib/model/note.rb +16 -0
- data/lib/relaton/bib/model/organization.rb +13 -0
- data/lib/relaton/bib/model/organization_type.rb +42 -0
- data/lib/relaton/bib/model/person.rb +36 -0
- data/lib/relaton/bib/model/phone.rb +14 -0
- data/lib/relaton/bib/model/place.rb +33 -0
- data/lib/relaton/bib/model/price.rb +14 -0
- data/lib/relaton/bib/model/relation.rb +43 -0
- data/lib/relaton/bib/model/series.rb +34 -0
- data/lib/relaton/bib/model/size.rb +23 -0
- data/lib/relaton/bib/model/source_locality_stack.rb +14 -0
- data/lib/relaton/bib/model/status.rb +27 -0
- data/lib/relaton/bib/model/structured_identifier.rb +48 -0
- data/lib/relaton/bib/model/subdivision.rb +16 -0
- data/lib/relaton/bib/model/title.rb +56 -0
- data/lib/relaton/bib/model/type/string_date.rb +48 -0
- data/lib/relaton/bib/model/uri.rb +18 -0
- data/lib/relaton/bib/model/validity.rb +16 -0
- data/lib/relaton/bib/model/version.rb +14 -0
- data/lib/relaton/bib/namespace_helper.rb +21 -0
- data/lib/relaton/bib/util.rb +18 -0
- data/lib/relaton/bib/version.rb +5 -0
- data/lib/relaton/bib.rb +45 -0
- data/relaton-bib.gemspec +11 -8
- metadata +125 -67
- data/lib/relaton_bib/bib_item_locality.rb +0 -175
- data/lib/relaton_bib/biblio_note.rb +0 -72
- data/lib/relaton_bib/biblio_version.rb +0 -46
- data/lib/relaton_bib/bibliographic_date.rb +0 -119
- data/lib/relaton_bib/bibliographic_item.rb +0 -668
- data/lib/relaton_bib/bibliographic_size.rb +0 -103
- data/lib/relaton_bib/bibtex_parser.rb +0 -246
- data/lib/relaton_bib/bibxml_parser.rb +0 -422
- data/lib/relaton_bib/classification.rb +0 -40
- data/lib/relaton_bib/config.rb +0 -16
- data/lib/relaton_bib/contribution_info.rb +0 -117
- data/lib/relaton_bib/contributor.rb +0 -277
- data/lib/relaton_bib/copyright_association.rb +0 -79
- data/lib/relaton_bib/deep_dup.rb +0 -30
- data/lib/relaton_bib/document_identifier.rb +0 -118
- data/lib/relaton_bib/document_relation.rb +0 -95
- data/lib/relaton_bib/document_relation_collection.rb +0 -57
- data/lib/relaton_bib/document_status.rb +0 -92
- data/lib/relaton_bib/document_type.rb +0 -52
- data/lib/relaton_bib/edition.rb +0 -55
- data/lib/relaton_bib/editorial_group.rb +0 -41
- data/lib/relaton_bib/extent.rb +0 -39
- data/lib/relaton_bib/forename.rb +0 -65
- data/lib/relaton_bib/formatted_ref.rb +0 -17
- data/lib/relaton_bib/formatted_string.rb +0 -133
- data/lib/relaton_bib/full_name.rb +0 -108
- data/lib/relaton_bib/hash_converter.rb +0 -568
- data/lib/relaton_bib/hit.rb +0 -52
- data/lib/relaton_bib/hit_collection.rb +0 -105
- data/lib/relaton_bib/ics.rb +0 -42
- data/lib/relaton_bib/image.rb +0 -95
- data/lib/relaton_bib/localized_string.rb +0 -149
- data/lib/relaton_bib/medium.rb +0 -76
- data/lib/relaton_bib/organization.rb +0 -165
- data/lib/relaton_bib/person.rb +0 -129
- data/lib/relaton_bib/place.rb +0 -203
- data/lib/relaton_bib/renderer/bibtex_builder.rb +0 -312
- data/lib/relaton_bib/renderer/bibxml.rb +0 -296
- data/lib/relaton_bib/series.rb +0 -119
- data/lib/relaton_bib/structured_identifier.rb +0 -173
- data/lib/relaton_bib/technical_committee.rb +0 -34
- data/lib/relaton_bib/typed_title_string.rb +0 -191
- data/lib/relaton_bib/typed_uri.rb +0 -57
- data/lib/relaton_bib/util.rb +0 -16
- data/lib/relaton_bib/validity.rb +0 -52
- data/lib/relaton_bib/version.rb +0 -3
- data/lib/relaton_bib/workers_pool.rb +0 -43
- data/lib/relaton_bib/workgroup.rb +0 -58
- data/lib/relaton_bib/xml_parser.rb +0 -718
- data/lib/relaton_bib.rb +0 -111
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module RelatonBib
|
|
4
|
-
# Document status.
|
|
5
|
-
class DocumentStatus
|
|
6
|
-
# @return [RelatonBib::DocumentStatus::Stage]
|
|
7
|
-
attr_reader :stage
|
|
8
|
-
|
|
9
|
-
# @return [RelatonBib::DocumentStatus::Stage, nil]
|
|
10
|
-
attr_reader :substage
|
|
11
|
-
|
|
12
|
-
# @return [String, nil]
|
|
13
|
-
attr_reader :iteration
|
|
14
|
-
|
|
15
|
-
# @param stage [String, Hash, RelatonBib::DocumentStatus::Stage]
|
|
16
|
-
# @param substage [String, Hash, nil, RelatonBib::DocumentStatus::Stage]
|
|
17
|
-
# @param iteration [String, nil]
|
|
18
|
-
def initialize(stage:, substage: nil, iteration: nil)
|
|
19
|
-
@stage = stage_new stage
|
|
20
|
-
@substage = stage_new substage
|
|
21
|
-
@iteration = iteration
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
# @param [Nokogiri::XML::Builder]
|
|
25
|
-
def to_xml(builder)
|
|
26
|
-
builder.status do
|
|
27
|
-
# FormattedString.instance_method(:to_xml).bind(status).call builder
|
|
28
|
-
builder.stage { |b| stage.to_xml b }
|
|
29
|
-
builder.substage { |b| substage.to_xml b } if substage
|
|
30
|
-
builder.iteration iteration unless iteration.to_s.empty?
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# @return [Hash]
|
|
35
|
-
def to_hash
|
|
36
|
-
hash = { "stage" => stage.to_hash }
|
|
37
|
-
hash["substage"] = substage.to_hash if substage
|
|
38
|
-
hash["iteration"] = iteration if iteration
|
|
39
|
-
hash
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# @param prefix [String]
|
|
43
|
-
# @return [String]
|
|
44
|
-
def to_asciibib(prefix = "")
|
|
45
|
-
pref = prefix.empty? ? prefix : "#{prefix}."
|
|
46
|
-
out = "#{pref}docstatus.stage:: #{stage.value}\n"
|
|
47
|
-
out += "#{pref}docstatus.substage:: #{substage.value}\n" if substage
|
|
48
|
-
out += "#{pref}docstatus.iteration:: #{iteration}\n" if iteration
|
|
49
|
-
out
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
private
|
|
53
|
-
|
|
54
|
-
# @param stg [RelatonBib::DocumentStatus::Stage, Hash, String, nil]
|
|
55
|
-
# @return [RelatonBib::DocumentStatus::Stage]
|
|
56
|
-
def stage_new(stg)
|
|
57
|
-
case stg
|
|
58
|
-
when Stage then stg
|
|
59
|
-
when Hash then self.class::Stage.new(**stg)
|
|
60
|
-
when String then self.class::Stage.new(value: stg)
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
class Stage
|
|
65
|
-
# @return [String]
|
|
66
|
-
attr_reader :value
|
|
67
|
-
|
|
68
|
-
# @return [String, nil]
|
|
69
|
-
attr_reader :abbreviation
|
|
70
|
-
|
|
71
|
-
# @param value [String]
|
|
72
|
-
# @param abbreviation [String, nil]
|
|
73
|
-
def initialize(value:, abbreviation: nil)
|
|
74
|
-
@value = value
|
|
75
|
-
@abbreviation = abbreviation
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
# @param [Nokogiri::XML::Builder]
|
|
79
|
-
def to_xml(builder)
|
|
80
|
-
builder.parent[:abbreviation] = abbreviation if abbreviation
|
|
81
|
-
builder.text value
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
# @return [Hash]
|
|
85
|
-
def to_hash
|
|
86
|
-
hash = { "value" => value }
|
|
87
|
-
hash["abbreviation"] = abbreviation if abbreviation
|
|
88
|
-
hash
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
module RelatonBib
|
|
2
|
-
class DocumentType
|
|
3
|
-
attr_reader :type, :abbreviation
|
|
4
|
-
|
|
5
|
-
#
|
|
6
|
-
# Initialize a DocumentType.
|
|
7
|
-
#
|
|
8
|
-
# @param [String] type document type
|
|
9
|
-
# @param [String, nil] abbreviation type abbreviation
|
|
10
|
-
#
|
|
11
|
-
def initialize(type:, abbreviation: nil)
|
|
12
|
-
@type = type
|
|
13
|
-
@abbreviation = abbreviation
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
#
|
|
17
|
-
# Build XML representation of the document type.
|
|
18
|
-
#
|
|
19
|
-
# @param [Nokogiri::XML::Builder] builder XML builder
|
|
20
|
-
#
|
|
21
|
-
def to_xml(builder)
|
|
22
|
-
xml = builder.doctype @type
|
|
23
|
-
xml[:abbreviation] = @abbreviation if @abbreviation
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
#
|
|
27
|
-
# Hash representation of the document type.
|
|
28
|
-
#
|
|
29
|
-
# @return [Hash]
|
|
30
|
-
#
|
|
31
|
-
def to_hash
|
|
32
|
-
hash = { "type" => @type }
|
|
33
|
-
hash["abbreviation"] = @abbreviation if @abbreviation
|
|
34
|
-
hash
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
#
|
|
38
|
-
# Asciibib representation of the document type.
|
|
39
|
-
#
|
|
40
|
-
# @param [String] prefix prefix
|
|
41
|
-
#
|
|
42
|
-
# @return [String] AsciiBib representation
|
|
43
|
-
#
|
|
44
|
-
def to_asciibib(prefix = "")
|
|
45
|
-
pref = prefix.empty? ? prefix : "#{prefix}."
|
|
46
|
-
pref += "doctype."
|
|
47
|
-
out = "#{pref}type:: #{@type}\n"
|
|
48
|
-
out += "#{pref}abbreviation:: #{@abbreviation}\n" if @abbreviation
|
|
49
|
-
out
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
data/lib/relaton_bib/edition.rb
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
module RelatonBib
|
|
2
|
-
class Edition
|
|
3
|
-
# @return [String] edition
|
|
4
|
-
attr_reader :content
|
|
5
|
-
|
|
6
|
-
# @return [String, nil] number
|
|
7
|
-
attr_reader :number
|
|
8
|
-
|
|
9
|
-
#
|
|
10
|
-
# Initialize edition.
|
|
11
|
-
#
|
|
12
|
-
# @param [String, Integer, Float] content edition
|
|
13
|
-
# @param [String, Integer, Float, nil] number number
|
|
14
|
-
#
|
|
15
|
-
def initialize(content:, number: nil)
|
|
16
|
-
@content = content.to_s
|
|
17
|
-
@number = number&.to_s
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
#
|
|
21
|
-
# Render edition as XML.
|
|
22
|
-
#
|
|
23
|
-
# @param [Nokogiri::XML::Builder] builder XML builder
|
|
24
|
-
#
|
|
25
|
-
def to_xml(builder)
|
|
26
|
-
node = builder.edition(content)
|
|
27
|
-
node[:number] = number if number
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
#
|
|
31
|
-
# Return edition as hash.
|
|
32
|
-
#
|
|
33
|
-
# @return [Hash] edition as hash.
|
|
34
|
-
#
|
|
35
|
-
def to_hash
|
|
36
|
-
hash = { "content" => content }
|
|
37
|
-
hash["number"] = number if number
|
|
38
|
-
hash
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
#
|
|
42
|
-
# Render edition as AsciiBib.
|
|
43
|
-
#
|
|
44
|
-
# @param [String] prefix prefix
|
|
45
|
-
#
|
|
46
|
-
# @return [String] edition as AsciiBib.
|
|
47
|
-
#
|
|
48
|
-
def to_asciibib(prefix = "")
|
|
49
|
-
pref = prefix.empty? ? "edition" : "#{prefix}.edition"
|
|
50
|
-
out = "#{pref}.content:: #{content}\n"
|
|
51
|
-
out += "#{pref}.number:: #{number}\n" if number
|
|
52
|
-
out
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
require "relaton_bib/technical_committee"
|
|
2
|
-
|
|
3
|
-
module RelatonBib
|
|
4
|
-
class EditorialGroup
|
|
5
|
-
include RelatonBib
|
|
6
|
-
|
|
7
|
-
# @return [Array<RelatonBib::TechnicalCommittee>]
|
|
8
|
-
attr_accessor :technical_committee
|
|
9
|
-
|
|
10
|
-
# @param technical_committee [Array<RelatonBib::TechnicalCommittee>]
|
|
11
|
-
def initialize(technical_committee)
|
|
12
|
-
@technical_committee = technical_committee
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
# @param builder [Nokogigi::XML::Builder]
|
|
16
|
-
def to_xml(builder)
|
|
17
|
-
builder.editorialgroup do |b|
|
|
18
|
-
technical_committee.each { |tc| tc.to_xml b }
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
# @return [Hash]
|
|
23
|
-
def to_hash
|
|
24
|
-
single_element_array technical_committee
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
# @param prefix [String]
|
|
28
|
-
# @return [String]
|
|
29
|
-
def to_asciibib(prefix = "")
|
|
30
|
-
pref = prefix.empty? ? "editorialgroup" : "#{prefix}.editorialgroup"
|
|
31
|
-
technical_committee.map do |tc|
|
|
32
|
-
tc.to_asciibib pref, technical_committee.size
|
|
33
|
-
end.join
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
# @return [true]
|
|
37
|
-
def presence?
|
|
38
|
-
technical_committee.any?
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
data/lib/relaton_bib/extent.rb
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
module RelatonBib
|
|
2
|
-
class Extent
|
|
3
|
-
attr_accessor :locality
|
|
4
|
-
|
|
5
|
-
#
|
|
6
|
-
# @param [Array<RelatonBib::Locality, RelatonBib::LocalityStack>] locality
|
|
7
|
-
#
|
|
8
|
-
def initialize(locality)
|
|
9
|
-
@locality = locality
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def to_xml(builder)
|
|
13
|
-
builder.extent do |b|
|
|
14
|
-
locality.each { |l| l.to_xml(b) }
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def to_hash
|
|
19
|
-
hash = Hash.new { |h, k| h[k] = [] }
|
|
20
|
-
locality.each_with_object(hash) do |l, obj|
|
|
21
|
-
k, v = l.to_hash.first
|
|
22
|
-
obj[k] << v
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def to_asciibib(prefix = "", count = 1)
|
|
27
|
-
pref = prefix.empty? ? "extent" : "#{prefix}.extent"
|
|
28
|
-
out = count > 1 ? "#{pref}::\n" : ""
|
|
29
|
-
locality.each do |l|
|
|
30
|
-
out += l.to_asciibib(pref, locality.size)
|
|
31
|
-
end
|
|
32
|
-
out
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def to_bibtex(item)
|
|
36
|
-
locality.map { |l| l.to_bibtex(item) }.join
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
data/lib/relaton_bib/forename.rb
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
module RelatonBib
|
|
2
|
-
class Forename < LocalizedString
|
|
3
|
-
# @return [String, nil]
|
|
4
|
-
attr_accessor :initial
|
|
5
|
-
|
|
6
|
-
#
|
|
7
|
-
# Initialize Forename instance
|
|
8
|
-
#
|
|
9
|
-
# @param [String] content content of forename, can be empty
|
|
10
|
-
# @param [Array<String>] language languages, `en`, `fr`, `de` etc.
|
|
11
|
-
# @param [Array<String>] script scripts `Latn`, `Cyrl` etc.
|
|
12
|
-
# @param [String, nil] initial initial of forename
|
|
13
|
-
#
|
|
14
|
-
def initialize(content: nil, language: [], script: [], initial: nil)
|
|
15
|
-
@initial = initial
|
|
16
|
-
super content, language, script
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def ==(other)
|
|
20
|
-
super && initial == other.initial
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def to_s
|
|
24
|
-
content.nil? ? initial : super
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
#
|
|
28
|
-
# Render forename to XML
|
|
29
|
-
#
|
|
30
|
-
# @param [Nokogiri::XML::Builder] builder XML builder
|
|
31
|
-
#
|
|
32
|
-
def to_xml(builder)
|
|
33
|
-
node = builder.forename { super }
|
|
34
|
-
node[:initial] = initial if initial
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
#
|
|
38
|
-
# Render forename to hash
|
|
39
|
-
#
|
|
40
|
-
# @return [Hash, String] forename hash or string representation
|
|
41
|
-
#
|
|
42
|
-
def to_hash
|
|
43
|
-
ls = super
|
|
44
|
-
hash = ls.is_a?(Hash) ? ls : { "content" => ls }
|
|
45
|
-
hash["initial"] = initial if initial
|
|
46
|
-
hash
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
#
|
|
50
|
-
# Render forename to asciibib
|
|
51
|
-
#
|
|
52
|
-
# @param [String] pref prefix
|
|
53
|
-
# @param [Integer] count size of array
|
|
54
|
-
#
|
|
55
|
-
# @return [String] asciibib string
|
|
56
|
-
#
|
|
57
|
-
def to_asciibib(pref, count = 1)
|
|
58
|
-
prf = pref.empty? ? pref : "#{pref}."
|
|
59
|
-
prf += "forename"
|
|
60
|
-
out = super prf, count
|
|
61
|
-
out += "#{prf}.initial:: #{initial}\n" if initial
|
|
62
|
-
out
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
require "relaton_bib/formatted_string"
|
|
2
|
-
|
|
3
|
-
module RelatonBib
|
|
4
|
-
class FormattedRef < FormattedString
|
|
5
|
-
# @param [Nokogiri::XML::Builder]
|
|
6
|
-
def to_xml(builder)
|
|
7
|
-
builder.formattedref { super }
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
# @param prefix [String]
|
|
11
|
-
# @return [String]
|
|
12
|
-
def to_asciibib(prefix = "")
|
|
13
|
-
pref = prefix.empty? ? "formattedref" : "#{prefix}.formattedref"
|
|
14
|
-
super pref
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "relaton_bib/localized_string"
|
|
4
|
-
|
|
5
|
-
module RelatonBib
|
|
6
|
-
# Formatted string
|
|
7
|
-
class FormattedString < LocalizedString
|
|
8
|
-
FORMATS = %w[text/plain text/html application/docbook+xml
|
|
9
|
-
application/tei+xml text/x-asciidoc text/markdown
|
|
10
|
-
application/x-metanorma+xml].freeze
|
|
11
|
-
|
|
12
|
-
# @return [String]
|
|
13
|
-
attr_reader :format
|
|
14
|
-
|
|
15
|
-
# @param content [String, Array<RelatonBib::LocalizedString>]
|
|
16
|
-
# @param language [String, nil] language code Iso639
|
|
17
|
-
# @param script [String, nil] script code Iso15924
|
|
18
|
-
# @param format [String] the content type
|
|
19
|
-
def initialize(content: "", language: nil, script: nil, format: "text/plain")
|
|
20
|
-
# if format && !FORMATS.include?(format)
|
|
21
|
-
# raise ArgumentError, %{Format "#{format}" is invalid.}
|
|
22
|
-
# end
|
|
23
|
-
|
|
24
|
-
@format = format
|
|
25
|
-
super(content, language, script)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def ==(other)
|
|
29
|
-
super && format == other.format
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# @param builder [Nokogiri::XML::Builder]
|
|
33
|
-
def to_xml(builder)
|
|
34
|
-
builder.parent["format"] = format if format
|
|
35
|
-
super
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
#
|
|
39
|
-
# Encode content.
|
|
40
|
-
#
|
|
41
|
-
# @param [String] cnt content
|
|
42
|
-
#
|
|
43
|
-
# @return [String] encoded content
|
|
44
|
-
#
|
|
45
|
-
def encode(cnt) # rubocop:disable Metrics/MethodLength
|
|
46
|
-
return escp(cnt) unless format == "text/html"
|
|
47
|
-
|
|
48
|
-
parts = cnt.scan(%r{
|
|
49
|
-
<(?<tago>\w+)(?<attrs>[^>]*)> | # tag open
|
|
50
|
-
</(?<tagc>\w+)> | # tag close
|
|
51
|
-
(?<cmt><!--.*?-->) | # comment
|
|
52
|
-
(?<cnt>.+?)(?=<|$) # content
|
|
53
|
-
}x)
|
|
54
|
-
scan_xml parts
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
#
|
|
58
|
-
# Scan XML and escape HTML entities.
|
|
59
|
-
#
|
|
60
|
-
# @param [Array<Array<String,nil>>] parts XML parts
|
|
61
|
-
#
|
|
62
|
-
# @return [String] output string
|
|
63
|
-
#
|
|
64
|
-
def scan_xml(parts) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
|
|
65
|
-
return "" unless parts.any?
|
|
66
|
-
|
|
67
|
-
out = ""
|
|
68
|
-
while parts.any? && (parts.first[3] || parts.first[4])
|
|
69
|
-
_, _, _, cmt, cnt = parts.shift
|
|
70
|
-
out += "#{cmt}#{escp(cnt)}"
|
|
71
|
-
end
|
|
72
|
-
unless out.empty?
|
|
73
|
-
out += scan_xml(parts) if parts.any? && parts.first[0]
|
|
74
|
-
return out
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
tago, attrs, tagc, = parts.shift
|
|
78
|
-
out = if tago && attrs && attrs[-1] == "/"
|
|
79
|
-
"<#{tago}#{attrs}>"
|
|
80
|
-
elsif tago
|
|
81
|
-
inr = scan_xml parts
|
|
82
|
-
_, _, tagc, = parts.shift
|
|
83
|
-
if tago == tagc
|
|
84
|
-
"<#{tago}#{attrs}>#{inr}</#{tagc}>"
|
|
85
|
-
else
|
|
86
|
-
"#{escp("<#{tago}#{attrs}>")}#{inr}#{escp("</#{tagc}>")}"
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
out += scan_xml(parts) if parts.any? && (parts.first[0] || parts.first[3] || parts.first[4])
|
|
90
|
-
out
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
# @return [Hash]
|
|
94
|
-
def to_hash
|
|
95
|
-
hash = super
|
|
96
|
-
return hash unless format
|
|
97
|
-
|
|
98
|
-
hash = { "content" => hash } unless hash.is_a? Hash
|
|
99
|
-
hash["format"] = format
|
|
100
|
-
hash
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
# @param prefix [String]
|
|
104
|
-
# @param count [Integer] number of elements
|
|
105
|
-
# @return [String]
|
|
106
|
-
def to_asciibib(prefix = "", count = 1, has_attrs = false)
|
|
107
|
-
has_attrs ||= !(format.nil? || format.empty?)
|
|
108
|
-
pref = prefix.empty? ? prefix : "#{prefix}."
|
|
109
|
-
# out = count > 1 ? "#{prefix}::\n" : ""
|
|
110
|
-
out = super
|
|
111
|
-
out += "#{pref}format:: #{format}\n" if format
|
|
112
|
-
out
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
#
|
|
116
|
-
# Remove HTML tags except <em>, <strong>, <stem>, <sup>, <sub>, <tt>, <br>, <p>.
|
|
117
|
-
# Replace <i> with <em>, <b> with <strong>.
|
|
118
|
-
#
|
|
119
|
-
# @param [String] str content
|
|
120
|
-
#
|
|
121
|
-
# @return [String] cleaned content
|
|
122
|
-
#
|
|
123
|
-
def cleanup(str)
|
|
124
|
-
return str unless format == "text/html"
|
|
125
|
-
|
|
126
|
-
str.gsub(/(?<=<)\w+:(?=\w+>)/, "").gsub(/(?<=<\/)\w+:(?=\w+>)/, "")
|
|
127
|
-
.gsub(/<i>/, "<em>").gsub(/<\/i>/, "</em>")
|
|
128
|
-
.gsub(/<b>/, "<strong>").gsub(/<\/b>/, "</strong>")
|
|
129
|
-
.gsub(/<(?!\/?(em|strong|stem|sup|sub|tt|br\s?\/|p|ol|ul|li))[^\s!]\/?.*?>/i, "")
|
|
130
|
-
.gsub(/\s+([.,:;!?<])/, "\\1").strip.squeeze(" ")
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
end
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
module RelatonBib
|
|
2
|
-
# Person's full name
|
|
3
|
-
class FullName
|
|
4
|
-
include RelatonBib
|
|
5
|
-
|
|
6
|
-
# @return [Array<RelatonBib::Forename>]
|
|
7
|
-
attr_accessor :forename
|
|
8
|
-
|
|
9
|
-
# @return [Array<RelatonBib::LocalizedString>]
|
|
10
|
-
attr_accessor :initials, :addition, :prefix
|
|
11
|
-
|
|
12
|
-
# @return [RelatonBib::LocalizedString, nil]
|
|
13
|
-
attr_accessor :surname, :abbreviation, :completename
|
|
14
|
-
|
|
15
|
-
#
|
|
16
|
-
# Initialize FullName instance
|
|
17
|
-
#
|
|
18
|
-
# @param surname [RelatonBib::LocalizedString, nil] surname or completename should be present
|
|
19
|
-
# @param abbreviation [RelatonBib::LocalizedString, nil] abbreviation
|
|
20
|
-
# @param forename [Array<RelatonBib::Forename>] forename
|
|
21
|
-
# @param initials [RelatonBib::LocalizedString, String, nil] string of initials
|
|
22
|
-
# @param addition [Array<RelatonBib::LocalizedString>] array of additions
|
|
23
|
-
# @param prefix [Array<RelatonBib::LocalizedString>] array of prefixes
|
|
24
|
-
# @param completename [RelatonBib::LocalizedString, nil] completename or surname should be present
|
|
25
|
-
#
|
|
26
|
-
def initialize(**args) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity
|
|
27
|
-
unless args[:surname] || args[:completename]
|
|
28
|
-
raise ArgumentError, "Should be given :surname or :completename"
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
@surname = args[:surname]
|
|
32
|
-
@abbreviation = args[:abbreviation]
|
|
33
|
-
@forename = args[:forename] || []
|
|
34
|
-
@initials = args[:initials].is_a?(String) ? LocalizedString.new(args[:initials]) : args[:initials]
|
|
35
|
-
@addition = args[:addition] || []
|
|
36
|
-
@prefix = args[:prefix] || []
|
|
37
|
-
@completename = args[:completename]
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def ==(other) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity
|
|
41
|
-
surname == other.surname && abbreviation == other.abbreviation &&
|
|
42
|
-
completename == other.completename && forename == other.forename &&
|
|
43
|
-
initials == other.initials && addition == other.addition &&
|
|
44
|
-
prefix == other.prefix
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
# @param opts [Hash]
|
|
48
|
-
# @option opts [Nokogiri::XML::Builder] :builder XML builder
|
|
49
|
-
# @option opts [String] :lang language
|
|
50
|
-
def to_xml(**opts) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
|
51
|
-
opts[:builder].name do |builder|
|
|
52
|
-
builder.abbreviation { abbreviation.to_xml builder } if abbreviation
|
|
53
|
-
if completename
|
|
54
|
-
builder.completename { completename.to_xml builder }
|
|
55
|
-
else
|
|
56
|
-
pref = prefix.select { |p| p.language&.include? opts[:lang] }
|
|
57
|
-
pref = prefix unless pref.any?
|
|
58
|
-
pref.each { |p| builder.prefix { p.to_xml builder } }
|
|
59
|
-
frnm = forename.select { |f| f.language&.include? opts[:lang] }
|
|
60
|
-
frnm = forename unless frnm.any?
|
|
61
|
-
frnm.each { |f| f.to_xml builder }
|
|
62
|
-
builder.send(:"formatted-initials") { initials.to_xml builder } if initials
|
|
63
|
-
builder.surname { surname.to_xml builder }
|
|
64
|
-
addn = addition.select { |a| a.language&.include? opts[:lang] }
|
|
65
|
-
addn = addition unless addn.any?
|
|
66
|
-
addn.each { |a| builder.addition { a.to_xml builder } }
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
# @return [Hash]
|
|
72
|
-
def to_hash # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
|
|
73
|
-
hash = {}
|
|
74
|
-
hash["abbreviation"] = abbreviation.to_hash if abbreviation
|
|
75
|
-
if forename.any? || initials
|
|
76
|
-
hash["given"] = {}
|
|
77
|
-
hash["given"]["forename"] = single_element_array(forename) if forename&.any?
|
|
78
|
-
hash["given"]["formatted_initials"] = initials.to_hash if initials
|
|
79
|
-
end
|
|
80
|
-
hash["surname"] = surname.to_hash if surname
|
|
81
|
-
hash["addition"] = single_element_array(addition) if addition&.any?
|
|
82
|
-
hash["prefix"] = single_element_array(prefix) if prefix&.any?
|
|
83
|
-
hash["completename"] = completename.to_hash if completename
|
|
84
|
-
hash
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
# @param pref [String]
|
|
88
|
-
# @return [String]
|
|
89
|
-
def to_asciibib(pref) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
|
|
90
|
-
prf = pref.empty? ? pref : "#{pref}."
|
|
91
|
-
prf += "name"
|
|
92
|
-
out = ""
|
|
93
|
-
out += abbreviation.to_asciibib "#{prf}.abbreviation" if abbreviation
|
|
94
|
-
given = "#{pref}.given"
|
|
95
|
-
out += forename.map do |fn|
|
|
96
|
-
fn.to_asciibib given, forename.size
|
|
97
|
-
end.join
|
|
98
|
-
out += initials.to_asciibib "#{given}.formatted-initials" if initials
|
|
99
|
-
out += surname.to_asciibib "#{prf}.surname" if surname
|
|
100
|
-
addition.each do |ad|
|
|
101
|
-
out += ad.to_asciibib "#{prf}.addition", addition.size
|
|
102
|
-
end
|
|
103
|
-
prefix.each { |pr| out += pr.to_asciibib "#{prf}.prefix", prefix.size }
|
|
104
|
-
out += completename.to_asciibib "#{prf}.completename" if completename
|
|
105
|
-
out
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
end
|