relaton-bib 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ module RelatonBib
2
+ class Medium
3
+ # @return [String, NilClass]
4
+ attr_reader :form, :size, :scale
5
+
6
+ # @param form [String, NilClass]
7
+ # @param size [String, NilClass]
8
+ # @param scale [String, NilClass]
9
+ def initialize(form: nil, size: nil, scale: nil)
10
+ @form = form
11
+ @size = size
12
+ @scale = scale
13
+ end
14
+
15
+ # @param builder [Nokogiri::XML::Builder]
16
+ def to_xml(builder)
17
+ builder.medium do
18
+ builder.form form if form
19
+ builder.size size if size
20
+ builder.scale scale if scale
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "relaton_bib/contributor"
4
+
5
+ module RelatonBib
6
+ # module OrgIdentifierType
7
+ # ORCID = 'orcid'
8
+ # URI = 'uri'
9
+ # end
10
+
11
+ # Organization identifier.
12
+ class OrgIdentifier
13
+ ORCID = "orcid"
14
+ URI = "uri"
15
+
16
+ # @return [String]
17
+ attr_reader :type
18
+
19
+ # @return [String]
20
+ attr_reader :value
21
+
22
+ # @param type [String] "orcid" or "uri"
23
+ # @param value [String]
24
+ def initialize(type, value)
25
+ unless [ORCID, URI].include? type
26
+ raise ArgumentError, 'Invalid type. It should be "orsid" or "uri".'
27
+ end
28
+
29
+ @type = type
30
+ @value = value
31
+ end
32
+
33
+ # @param builder [Nokogiri::XML::Builder]
34
+ def to_xml(builder)
35
+ builder.identifier(value, type: type)
36
+ end
37
+ end
38
+
39
+ # Organization.
40
+ class Organization < Contributor
41
+ # @return [RelatonBib::LocalizedString]
42
+ attr_reader :name
43
+
44
+ # @return [RelatonBib::LocalizedString]
45
+ attr_reader :abbreviation
46
+
47
+ # @return [RelatonBib::LocalizedString]
48
+ attr_reader :subdivision
49
+
50
+ # @return [Array<RelatonBib::OrgIdentifier>]
51
+ attr_reader :identifiers
52
+
53
+ def hash2locstr(name)
54
+ name.is_a?(Hash) ? LocalizedString.new(name[:content], name[:language], name[:script]) : LocalizedString.new(name)
55
+ end
56
+
57
+ # @param name [String, Array<String>]
58
+ # @param abbreviation [RelatoBib::LocalizedStrig, String]
59
+ # @param subdivision [RelatoBib::LocalizedStrig, String]
60
+ # @param url [String]
61
+ # @param identifiers [Array<RelatonBib::OrgIdentifier>]
62
+ # @param contacts [Array<RelatonBib::Address, RelatonBib::Phone>]
63
+ def initialize(**args)
64
+ raise ArgumentError, "missing keyword: name" unless args[:name]
65
+
66
+ super(url: args[:url], contacts: args.fetch(:contacts, []))
67
+
68
+ @name = if args[:name].is_a?(Array)
69
+ args[:name].map { |n| hash2locstr(n) }
70
+ else
71
+ [hash2locstr(args[:name])]
72
+ end
73
+
74
+ @abbreviation = if args[:abbreviation].is_a?(String)
75
+ LocalizedString.new(args[:abbreviation])
76
+ else
77
+ args[:abbreviation]
78
+ end
79
+
80
+ @subdivision = if args[:subdivision].is_a?(String)
81
+ LocalizedString.new(args[:subdivision])
82
+ else
83
+ args[:subdivision]
84
+ end
85
+
86
+ @identifiers = args.fetch(:identifiers, [])
87
+ end
88
+
89
+ # @param builder [Nokogiri::XML::Builder]
90
+ def to_xml(builder)
91
+ builder.organization do
92
+ name.each do |n|
93
+ builder.name { |b| n.to_xml b }
94
+ end
95
+ builder.subdivision { |s| subdivision.to_xml s } if subdivision
96
+ builder.abbreviation { |a| abbreviation.to_xml a } if abbreviation
97
+ builder.uri url if uri
98
+ identifiers.each { |identifier| identifier.to_xml builder }
99
+ super
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,131 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "relaton_bib/contributor"
4
+
5
+ module RelatonBib
6
+ # Person's full name
7
+ class FullName
8
+ # @return [Array<RelatonBib::LocalizedString>]
9
+ attr_accessor :forenames
10
+
11
+ # @return [Array<RelatonBib::LocalizedString>]
12
+ attr_accessor :initials
13
+
14
+ # @return [RelatonBib::LocalizedString]
15
+ attr_accessor :surname
16
+
17
+ # @return [Array<RelatonBib::LocalizedString>]
18
+ attr_accessor :additions
19
+
20
+ # @return [Array<RelatonBib::LocalizedString>]
21
+ attr_accessor :prefix
22
+
23
+ # @return [RelatonBib::LocalizedString]
24
+ attr_reader :completename
25
+
26
+ # @param surname [RelatonBib::LocalizedString]
27
+ # @param forenames [Array<RelatonBib::LocalizedString>]
28
+ # @param initials [Array<RelatonBib::LocalizedString>]
29
+ # @param additions [Array<RelatonBib::LocalizedString>]
30
+ # @param prefix [Array<RelatonBib::LocalizedString>]
31
+ # @param completename [RelatonBib::LocalizedString]
32
+ def initialize(**args)
33
+ unless args[:surname] || args[:completename]
34
+ raise ArgumentError, "Should be given :surname or :completename"
35
+ end
36
+
37
+ @surname = args[:surname]
38
+ @forenames = args.fetch :forenames, []
39
+ @initials = args.fetch :initials, []
40
+ @additions = args.fetch :additions, []
41
+ @prefix = args.fetch :prefix, []
42
+ @completename = args[:completename]
43
+ end
44
+
45
+ # @param builder [Nokogiri::XML::Builder]
46
+ def to_xml(builder)
47
+ builder.name do
48
+ if completename
49
+ builder.completename { completename.to_xml builder }
50
+ else
51
+ prefix.each { |p| builder.prefix { p.to_xml builder } }
52
+ initials.each { |i| builder.initial { i.to_xml builder } }
53
+ additions.each { |a| builder.addition { a.to_xml builder } }
54
+ builder.surname { surname.to_xml builder }
55
+ forenames.each { |f| builder.forename { f.to_xml builder } }
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ # Person identifier type.
62
+ module PersonIdentifierType
63
+ ISNI = "isni"
64
+ URI = "uri"
65
+
66
+ # Checks type.
67
+ # @param type [String]
68
+ # @raise [ArgumentError] if type isn't "isni" or "uri"
69
+ def self.check(type)
70
+ unless [ISNI, URI].include? type
71
+ raise ArgumentError, 'Invalid type. It should be "isni" or "uri".'
72
+ end
73
+ end
74
+ end
75
+
76
+ # Person identifier.
77
+ class PersonIdentifier
78
+ # @return [RelatonBib::PersonIdentifierType::ISNI, RelatonBib::PersonIdentifierType::URI]
79
+ attr_accessor :type
80
+
81
+ # @return [String]
82
+ attr_accessor :value
83
+
84
+ # @param type [RelatonBib::PersonIdentifierType::ISNI, RelatonBib::PersonIdentifierType::URI]
85
+ # @param value [String]
86
+ def initialize(type, value)
87
+ PersonIdentifierType.check type
88
+
89
+ @type = type
90
+ @value = value
91
+ end
92
+
93
+ # @param builser [Nokogiri::XML::Builder]
94
+ def to_xml(builder)
95
+ builder.identifier value, type: type
96
+ end
97
+ end
98
+
99
+ # Person class.
100
+ class Person < Contributor
101
+ # @return [RelatonBib::FullName]
102
+ attr_accessor :name
103
+
104
+ # @return [Array<RelatonBib::Affilation>]
105
+ attr_accessor :affiliation
106
+
107
+ # @return [Array<RelatonBib::PersonIdentifier>]
108
+ attr_accessor :identifiers
109
+
110
+ # @param name [RelatonBib::FullName]
111
+ # @param affiliation [Array<RelatonBib::Affiliation>]
112
+ # @param contacts [Array<RelatonBib::Address, RelatonBib::Phone>]
113
+ # @param identifiers [Array<RelatonBib::PersonIdentifier>]
114
+ def initialize(name:, affiliation: [], contacts: [], identifiers: [])
115
+ super(contacts: contacts)
116
+ @name = name
117
+ @affiliation = affiliation
118
+ @identifiers = identifiers
119
+ end
120
+
121
+ # @param builder [Nokogiri::XML::Builder]
122
+ def to_xml(builder)
123
+ builder.person do
124
+ name.to_xml builder
125
+ affiliation.each { |a| a.to_xml builder }
126
+ identifiers.each { |id| id.to_xml builder }
127
+ contacts.each { |contact| contact.to_xml builder }
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RelatonBib
4
+ #
5
+ # Series class.
6
+ #
7
+ class Series
8
+ TYPES = %w[main alt].freeze
9
+
10
+ # @return [String, NilClass] allowed values: "main" or "alt"
11
+ attr_reader :type
12
+
13
+ # @return [RelatonBib::FormattedRef, NilClass]
14
+ attr_reader :formattedref
15
+
16
+ # @return [RelatonBib::FormattedString, NilClass] title
17
+ attr_reader :title
18
+
19
+ # @return [String, NilClass]
20
+ attr_reader :place
21
+
22
+ # @return [String, NilClass]
23
+ attr_reader :organization
24
+
25
+ # @return [RelatonBib::LocalizedString, NilClass]
26
+ attr_reader :abbreviation
27
+
28
+ # @return [String, NilClass] date or year
29
+ attr_reader :from
30
+
31
+ # @return [String, NilClass] date or year
32
+ attr_reader :to
33
+
34
+ # @return [String, NilClass]
35
+ attr_reader :number
36
+
37
+ # @return [String, NilClass]
38
+ attr_reader :partnumber
39
+
40
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
41
+
42
+ # @param type [String, NilClass] title or formattedref argument should be passed
43
+ # @param formattedref [RelatonBib::FormattedRef, NilClass]
44
+ # @param title [RelatonBib::TypedTitleString, NilClass]
45
+ # @param place [String, NilClass]
46
+ # @param orgaization [String, NilClass]
47
+ # @param abbreviation [RelatonBib::LocalizedString, NilClass]
48
+ # @param from [String, NilClass]
49
+ # @param to [String, NilClass]
50
+ # @param number [String, NilClass]
51
+ # @param partnumber [String, NilClass]
52
+ def initialize(**args)
53
+ unless args[:title].is_a?(RelatonBib::TypedTitleString) || args[:formattedref]
54
+ raise ArgumentError, "argument `title` or `formattedref` should present"
55
+ end
56
+
57
+ if args[:type] && !TYPES.include?(args[:type])
58
+ raise ArgumentError, "invalid argument `type`"
59
+ end
60
+
61
+ @type = args[:type] # if %w[main alt].include? args[:type]
62
+ @title = args[:title]
63
+ @formattedref = args[:formattedref]
64
+ @place = args[:place]
65
+ @organization = args[:organization]
66
+ @abbreviation = args[:abbreviation]
67
+ @from = args[:from]
68
+ @to = args[:to]
69
+ @number = args[:number]
70
+ @partnumber = args[:partnumber]
71
+ end
72
+ # rubocop:enable Metrics/MethodLength
73
+
74
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
75
+
76
+ # @param builder [Nokogiri::XML::Builder]
77
+ def to_xml(builder)
78
+ builder.series type: type do
79
+ if formattedref
80
+ formattedref.to_xml builder
81
+ else
82
+ builder.title { title.to_xml builder }
83
+ builder.place place if place
84
+ builder.organization organization if organization
85
+ builder.abbreviation { abbreviation.to_xml builder } if abbreviation
86
+ builder.from from if from
87
+ builder.to to if to
88
+ builder.number number if number
89
+ builder.partnumber partnumber if partnumber
90
+ end
91
+ end
92
+ end
93
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
94
+ # rubocop:enable Metrics/PerceivedComplexity
95
+ end
96
+ end
@@ -0,0 +1,41 @@
1
+ module RelatonBib
2
+ class TypedTitleString
3
+ TITLE_TYPES = %w[alternative original unofficial subtitle main].freeze
4
+
5
+ # @return [String]
6
+ attr_reader :type
7
+
8
+ # @return [RelatonBib::FormattedString]
9
+ attr_reader :title
10
+
11
+ # @param type [String]
12
+ # @param title [RelatonBib::FormattedString, Hash]
13
+ # @param content [String]
14
+ # @param language [String]
15
+ # @param script [String]
16
+ def initialize(**args)
17
+ if args[:type] && !TITLE_TYPES.include?(args[:type])
18
+ raise ArgumentError, %{The type #{args[:type]} is invalid.}
19
+ end
20
+
21
+ unless args[:title] || args[:content]
22
+ raise ArgumentError, %{Keyword "title" or "content" should be passed.}
23
+ end
24
+
25
+ @type = args[:type]
26
+
27
+ # if args[:title]
28
+ # @title = args[:title]
29
+ # else
30
+ fsargs = args.select { |k, _v| %i[content language script format].include? k }
31
+ @title = args.fetch :title, FormattedString.new(fsargs)
32
+ # end
33
+ end
34
+
35
+ # @param builder [Nokogiri::XML::Builder]
36
+ def to_xml(builder)
37
+ builder.parent[:type] = type if type
38
+ title.to_xml builder
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,20 @@
1
+ module RelatonBib
2
+ # Typed URI
3
+ class TypedUri
4
+ # @return [Symbol] :src/:obp/:rss
5
+ attr_reader :type
6
+ # @retutn [URI]
7
+ attr_reader :content
8
+
9
+ # @param type [String] src/obp/rss
10
+ # @param content [String]
11
+ def initialize(type:, content:)
12
+ @type = type
13
+ @content = URI content if content
14
+ end
15
+
16
+ def to_xml(builder)
17
+ builder.uri(content.to_s, type: type)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,31 @@
1
+ module RelatonBib
2
+ class Validity
3
+ # @return [Time, NilClass]
4
+ attr_reader :begins
5
+
6
+ # @return [Time, NilClass]
7
+ attr_reader :ends
8
+
9
+ # @return [Time, NilClass]
10
+ attr_reader :revision
11
+
12
+ # @param begins [Time, NilClass]
13
+ # @param ends [Time, NilClass]
14
+ # @param revision [Time, NilClass]
15
+ def initialize(begins: nil, ends: nil, revision: nil)
16
+ @begins = begins
17
+ @ends = ends
18
+ @revision = revision
19
+ end
20
+
21
+ # @param [Nokogiri::XML::Builder]
22
+ def to_xml(builder)
23
+ format = "%Y-%m-%d %H:%M"
24
+ builder.validity do
25
+ builder.validityBegins begins.strftime(format) if begins
26
+ builder.validityEnds ends.strftime(format) if ends
27
+ builder.validityRevision revision.strftime(format) if revision
28
+ end
29
+ end
30
+ end
31
+ end