relaton-bib 1.20.7 → 2.0.0.pre.alpha.1
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/.rubocop.yml +1 -1
- data/README.adoc +183 -154
- data/bin/console +1 -1
- data/grammars/basicdoc.rng +1516 -645
- data/grammars/biblio-standoc.rng +100 -20
- data/grammars/biblio.rng +959 -356
- data/grammars/versions.json +10 -10
- data/lib/relaton/bib/hash_parser_v1.rb +711 -0
- data/lib/relaton/bib/item_data.rb +168 -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 +29 -0
- data/lib/relaton/bib/model/depiction.rb +14 -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/editorial_group.rb +14 -0
- data/lib/relaton/bib/model/ext.rb +29 -0
- data/lib/relaton/bib/model/extent.rb +16 -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 +14 -0
- data/lib/relaton/bib/model/image.rb +28 -0
- data/lib/relaton/bib/model/item.rb +129 -0
- data/lib/relaton/bib/model/item_base.rb +19 -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 +12 -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 +32 -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 +14 -0
- data/lib/relaton/bib/model/technical_committee.rb +14 -0
- data/lib/relaton/bib/model/title.rb +18 -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/model/workgroup.rb +20 -0
- data/lib/relaton/bib/parser/rfc_address.rb +60 -0
- data/lib/relaton/bib/parser/rfc_contacts.rb +35 -0
- data/lib/relaton/bib/parser/rfc_docidentifier.rb +70 -0
- data/lib/relaton/bib/parser/rfc_organization.rb +31 -0
- data/lib/relaton/bib/parser/rfc_person.rb +42 -0
- data/lib/relaton/bib/parser/rfc_reference.rb +143 -0
- data/lib/relaton/bib/parser/rfc_referencegroup.rb +45 -0
- data/lib/relaton/bib/parser/rfc_shared.rb +23 -0
- data/lib/relaton/bib/renderer/bibtex_builder.rb +348 -0
- data/lib/relaton/bib/renderer/rfc.rb +297 -0
- data/lib/relaton/bib/util.rb +18 -0
- data/lib/relaton/bib/version.rb +5 -0
- data/lib/{relaton_bib.rb → relaton/bib.rb} +47 -36
- data/lib/{relaton_bib → relaton}/bibtex_parser.rb +24 -27
- data/lib/{relaton_bib → relaton}/bibxml_parser.rb +43 -46
- data/lib/{relaton_bib → relaton}/hit.rb +3 -3
- data/lib/{relaton_bib → relaton}/hit_collection.rb +2 -2
- data/lib/{relaton_bib → relaton}/workers_pool.rb +1 -1
- data/lib/{relaton_bib → relaton}/xml_parser.rb +49 -51
- data/relaton-bib.gemspec +8 -8
- metadata +95 -74
- 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/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/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/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/workgroup.rb +0 -58
- /data/lib/{relaton_bib → relaton}/deep_dup.rb +0 -0
@@ -1,118 +0,0 @@
|
|
1
|
-
module RelatonBib
|
2
|
-
# Document identifier.
|
3
|
-
class DocumentIdentifier
|
4
|
-
# @return [String]
|
5
|
-
attr_reader :id
|
6
|
-
|
7
|
-
# @return [String, nil]
|
8
|
-
attr_reader :type, :scope, :language, :script
|
9
|
-
|
10
|
-
# @param type [Boolean, nil]
|
11
|
-
attr_reader :primary
|
12
|
-
|
13
|
-
# @param id [String]
|
14
|
-
# @param type [String, nil]
|
15
|
-
# @param scope [String, nil]
|
16
|
-
# @param primary [Bolean, nil]
|
17
|
-
# @param language [String, nil]
|
18
|
-
def initialize(**args)
|
19
|
-
@id = args[:id]
|
20
|
-
@type = args[:type]
|
21
|
-
@scope = args[:scope]
|
22
|
-
@primary = args[:primary]
|
23
|
-
@language = args[:language]
|
24
|
-
@script = args[:script]
|
25
|
-
end
|
26
|
-
|
27
|
-
# in docid manipulations, assume ISO as the default: id-part:year
|
28
|
-
def remove_part
|
29
|
-
case @type
|
30
|
-
when "Chinese Standard" then @id.sub!(/\.\d+/, "")
|
31
|
-
when "URN" then remove_urn_part
|
32
|
-
else @id.sub!(/-[^:]+/, "")
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def remove_date
|
37
|
-
case @type
|
38
|
-
when "Chinese Standard" then @id.sub!(/-[12]\d\d\d/, "")
|
39
|
-
when "URN"
|
40
|
-
@id.sub!(/^(urn:iec:std:[^:]+:[^:]+:)[^:]*/, '\1')
|
41
|
-
else @id.sub!(/:[12]\d\d\d/, "")
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def all_parts
|
46
|
-
if type == "URN"
|
47
|
-
@id.sub!(%r{^(urn:iec:std(?::[^:]*){4}).*}, '\1:ser')
|
48
|
-
else
|
49
|
-
@id += " (all parts)"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
#
|
54
|
-
# Add docidentifier xml element
|
55
|
-
#
|
56
|
-
# @param opts [Hash]
|
57
|
-
# @option opts [Nokogiri::XML::Builder] :builder XML builder
|
58
|
-
# @option opts [String] :lang language
|
59
|
-
def to_xml(**opts) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
60
|
-
lid = if type == "URN" && opts[:lang]
|
61
|
-
id.sub %r{(?<=:)(?:\w{2},)*?(#{opts[:lang]})(?:,\w{2})*}, '\1'
|
62
|
-
else id
|
63
|
-
end
|
64
|
-
element = opts[:builder].docidentifier { |b| b.parent.inner_html = lid }
|
65
|
-
element[:type] = type if type
|
66
|
-
element[:scope] = scope if scope
|
67
|
-
element[:primary] = primary if primary
|
68
|
-
element[:language] = language if language
|
69
|
-
element[:script] = script if script
|
70
|
-
end
|
71
|
-
|
72
|
-
# @return [Hash]
|
73
|
-
def to_hash # rubocop:disable Metrics/AbcSize
|
74
|
-
hash = { "id" => id }
|
75
|
-
hash["type"] = type if type
|
76
|
-
hash["scope"] = scope if scope
|
77
|
-
hash["primary"] = primary if primary
|
78
|
-
hash["language"] = language if language
|
79
|
-
hash["script"] = script if script
|
80
|
-
hash
|
81
|
-
end
|
82
|
-
|
83
|
-
# @param prefix [String]
|
84
|
-
# @param count [Integer] number of docids
|
85
|
-
# @return [String]
|
86
|
-
def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize
|
87
|
-
pref = prefix.empty? ? prefix : "#{prefix}."
|
88
|
-
return "#{pref}docid:: #{id}\n" unless type || scope
|
89
|
-
|
90
|
-
out = count > 1 ? "#{pref}docid::\n" : ""
|
91
|
-
out += "#{pref}docid.type:: #{type}\n" if type
|
92
|
-
out += "#{pref}docid.scope:: #{scope}\n" if scope
|
93
|
-
out += "#{pref}docid.primary:: #{primary}\n" if primary
|
94
|
-
out += "#{pref}docid.language:: #{language}\n" if language
|
95
|
-
out += "#{pref}docid.script:: #{script}\n" if script
|
96
|
-
out + "#{pref}docid.id:: #{id}\n"
|
97
|
-
end
|
98
|
-
|
99
|
-
private
|
100
|
-
|
101
|
-
def remove_urn_part # rubocop:disable Metrics/MethodLength
|
102
|
-
@id.sub!(%r{^
|
103
|
-
(urn:iso:std:[^:]+ # ISO prefix and originator
|
104
|
-
(?::(?:data|guide|isp|iwa|pas|r|tr|ts|tta)) # type
|
105
|
-
?:\d+) # docnumber
|
106
|
-
(?::-[^:]+)? # partnumber
|
107
|
-
(?::(draft|cancelled|stage-[^:]+))? # status
|
108
|
-
(?::ed-\d+)?(?::v[^:]+)? # edition and version
|
109
|
-
(?::\w{2}(?:,\w{2})*)? # langauge
|
110
|
-
}x, '\1') # remove partnumber, status, version, and language
|
111
|
-
@id.sub!(%r{^
|
112
|
-
(urn:iec:std:[^:]+ # IEC prefix and originator
|
113
|
-
:\d+) # docnumber
|
114
|
-
(?:-[^:]+)? # partnumber
|
115
|
-
}x, '\1') # remove partnumber
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
@@ -1,95 +0,0 @@
|
|
1
|
-
module RelatonBib
|
2
|
-
# Documett relation
|
3
|
-
class DocumentRelation
|
4
|
-
include RelatonBib
|
5
|
-
|
6
|
-
TYPES = %w[
|
7
|
-
includes includedIn hasPart partOf merges mergedInto splits splitInto
|
8
|
-
instanceOf hasInstance exemplarOf hasExemplar manifestationOf
|
9
|
-
hasManifestation reproductionOf hasReproduction reprintOf hasReprint
|
10
|
-
expressionOf hasExpression translatedFrom hasTranslation arrangementOf
|
11
|
-
hasArrangement abridgementOf hasAbridgement annotationOf hasAnnotation
|
12
|
-
draftOf hasDraft editionOf hasEdition updates updatedBy derivedFrom
|
13
|
-
derives describes describedBy catalogues cataloguedBy hasSuccessor
|
14
|
-
successorOf adaptedFrom hasAdaptation adoptedFrom adoptedAs reviewOf
|
15
|
-
hasReview commentaryOf hasCommentary related hasComplement complementOf
|
16
|
-
obsoletes obsoletedBy cites isCitedIn
|
17
|
-
].freeze
|
18
|
-
|
19
|
-
# @return [String]
|
20
|
-
attr_accessor :type
|
21
|
-
|
22
|
-
# @return [RelatonBib::FormattedString, nil]
|
23
|
-
attr_reader :description
|
24
|
-
|
25
|
-
# @return [String]
|
26
|
-
# attr_reader :identifier, :url
|
27
|
-
|
28
|
-
# @return [RelatonBib::BibliographicItem]
|
29
|
-
attr_reader :bibitem
|
30
|
-
|
31
|
-
# @return [Array<RelatonBib::Locality, RelatonBib::LocalityStack>]
|
32
|
-
attr_reader :locality
|
33
|
-
|
34
|
-
# @return [Array<RelatonBib::SourceLocality,
|
35
|
-
# RelatonBib::SourceLocalityStack>]
|
36
|
-
attr_reader :source_locality
|
37
|
-
|
38
|
-
# @param type [String]
|
39
|
-
# @param description [RelatonBib::FormattedString, nil]
|
40
|
-
# @param bibitem [RelatonBib::BibliographicItem,
|
41
|
-
# RelatonIso::IsoBibliographicItem]
|
42
|
-
# @param locality [Array<RelatonBib::Locality>]
|
43
|
-
# @param locality_stack [Array<RelatonBib::LocalityStack>]
|
44
|
-
# @param source_locality [Array<RelatonBib::SourceLocality,
|
45
|
-
# RelatonBib::SourceLocalityStack>]
|
46
|
-
def initialize(type:, bibitem:, **args)
|
47
|
-
type = "obsoletes" if type == "Now withdrawn"
|
48
|
-
unless self.class::TYPES.include? type
|
49
|
-
Util.warn "Invalid relation type: `#{type}`"
|
50
|
-
end
|
51
|
-
@type = type
|
52
|
-
@description = args[:description]
|
53
|
-
@locality = args[:locality] || args[:locality_stack] || []
|
54
|
-
@source_locality = args[:source_locality] || args[:source_locality_stack] || []
|
55
|
-
@bibitem = bibitem
|
56
|
-
end
|
57
|
-
|
58
|
-
# @param builder [Nokogiri::XML::Builder]
|
59
|
-
def to_xml(builder, **opts)
|
60
|
-
opts.delete :bibdata
|
61
|
-
opts.delete :note
|
62
|
-
builder.relation(type: type) do
|
63
|
-
builder.description { description.to_xml builder } if description
|
64
|
-
bibitem.to_xml(**opts.merge(builder: builder, embedded: true))
|
65
|
-
locality.each { |l| l.to_xml builder }
|
66
|
-
source_locality.each { |l| l.to_xml builder }
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
# @return [Hash]
|
71
|
-
def to_hash # rubocop:disable Metrics/AbcSize
|
72
|
-
hash = { "type" => type, "bibitem" => bibitem.to_hash(embedded: true) }
|
73
|
-
hash["description"] = description.to_hash if description
|
74
|
-
locality.each_with_object(hash) do |l, obj|
|
75
|
-
k, v = l.to_hash.first
|
76
|
-
hash[k] ||= []
|
77
|
-
hash[k] << v
|
78
|
-
end
|
79
|
-
if source_locality&.any?
|
80
|
-
hash["source_locality"] = single_element_array(source_locality)
|
81
|
-
end
|
82
|
-
hash
|
83
|
-
end
|
84
|
-
|
85
|
-
# @param prefix [String]
|
86
|
-
# @return [String]
|
87
|
-
def to_asciibib(prefix = "")
|
88
|
-
pref = prefix.empty? ? prefix : prefix + "."
|
89
|
-
out = "#{prefix}.type:: #{type}\n"
|
90
|
-
out += description.to_asciibib "#{pref}desctiption" if description
|
91
|
-
out += bibitem.to_asciibib "#{pref}bibitem" if bibitem
|
92
|
-
out
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RelatonBib
|
4
|
-
# Document relation collection
|
5
|
-
class DocRelationCollection
|
6
|
-
extend Forwardable
|
7
|
-
|
8
|
-
def_delegators :@array, :<<, :[], :first, :last, :empty?, :any?, :size,
|
9
|
-
:each, :detect, :map, :reduce, :length, :unshift, :max_by
|
10
|
-
|
11
|
-
# @param relation [Array<RelatonBib::DocumentRelation, Hash>]
|
12
|
-
# @option relation [String] :type
|
13
|
-
# @option relation [String] :identifier
|
14
|
-
# @option relation [String, NIllClass] :url (nil)
|
15
|
-
# @option relation [Array<RelatonBib::Locality, RelatonBib::LocalityStack>] :locality
|
16
|
-
# @option relation [Array<RelatonBib::SourceLocality, RelatonBib::SourceLocalityStack>] :source_locality
|
17
|
-
# @option relation [RelatonBib::BibliographicItem, nil] :bibitem (nil)
|
18
|
-
def initialize(relation)
|
19
|
-
@array = relation.map { |r| r.is_a?(Hash) ? DocumentRelation.new(**r) : r }
|
20
|
-
end
|
21
|
-
|
22
|
-
#
|
23
|
-
# Returns new DocumentRelationCollection with selected relations.
|
24
|
-
#
|
25
|
-
# @example Select relations with type "obsoletes"
|
26
|
-
# relations.select { |r| r.type == "obsoletes" }
|
27
|
-
# #=> <RelatonBib::DocRelationCollection:0x00007f9a0191d5f0 @array=[...]>
|
28
|
-
#
|
29
|
-
# @return [RelatonBib::DocRelationCollection] new DocumentRelationCollection
|
30
|
-
# with selected relations
|
31
|
-
#
|
32
|
-
def select(&block)
|
33
|
-
arr = @array.select(&block)
|
34
|
-
self.class.new arr
|
35
|
-
end
|
36
|
-
|
37
|
-
# @todo We don't have replace type anymore. Suppose we should update this
|
38
|
-
# method or delete it.
|
39
|
-
#
|
40
|
-
# @return [RelatonBib::DocRelationCollection]
|
41
|
-
def replaces
|
42
|
-
DocRelationCollection.new(@array.select { |r| r.type == "replace" })
|
43
|
-
end
|
44
|
-
|
45
|
-
# @param prefix [String]
|
46
|
-
# @return [String]
|
47
|
-
def to_asciibib(prefix = "")
|
48
|
-
pref = prefix.empty? ? "relation" : "#{prefix}.relation"
|
49
|
-
out = ""
|
50
|
-
@array.each do |r|
|
51
|
-
out += size > 1 ? "#{pref}::\n" : ""
|
52
|
-
out += r.to_asciibib pref
|
53
|
-
end
|
54
|
-
out
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -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
|