Module: RIFCS
- Included in:
- Activity, Collection, Party, Service
- Defined in:
- lib/rif-cs.rb,
lib/rif-cs/party.rb,
lib/rif-cs/service.rb,
lib/rif-cs/activity.rb,
lib/rif-cs/collection.rb
Defined Under Namespace
Modules: Activity, Collection, Party, Service
Class Method Summary
collapse
-
.addresses(addr_list, xml) ⇒ Object
-
.camelize(lower_case_and_underscored_word) ⇒ Object
-
.coverage(list, xml) ⇒ Object
-
.electronic_addresses(addr_list, xml) ⇒ Object
-
.existence_dates(list, xml) ⇒ Object
-
.list_of(list, name, xml) ⇒ Object
-
.locations(list, xml) ⇒ Object
-
.names(list, xml) ⇒ Object
-
.physical_addresses(addr_list, xml) ⇒ Object
-
.related_info(list, xml) ⇒ Object
-
.related_objects(obj, xml) ⇒ Object
-
.rights(list, xml) ⇒ Object
-
.spatials(spatial_list, xml) ⇒ Object
-
.subjects(list, xml) ⇒ Object
-
.temporals(temp_list, xml) ⇒ Object
Instance Method Summary
collapse
Class Method Details
.addresses(addr_list, xml) ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'lib/rif-cs.rb', line 42
def self.addresses(addr_list, xml)
return if addr_list.nil? or addr_list.empty?
xml.address_ do
addr_list.each do |addr|
electronic_addresses(addr[:electronic], xml)
physical_addresses(addr[:physical], xml)
end
end
end
|
.camelize(lower_case_and_underscored_word) ⇒ Object
8
9
10
|
# File 'lib/rif-cs.rb', line 8
def self.camelize(lower_case_and_underscored_word)
lower_case_and_underscored_word.to_s.gsub(/(?:_)(.)/) { $1.upcase }
end
|
.coverage(list, xml) ⇒ Object
77
78
79
80
81
82
83
84
85
|
# File 'lib/rif-cs.rb', line 77
def self.coverage(list, xml)
return if list.nil? or list.empty?
list.each do |coverage|
xml.coverage_ do
spatials(coverage[:spatials], xml)
temporals(coverage[:temporals], xml)
end
end
end
|
.electronic_addresses(addr_list, xml) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/rif-cs.rb', line 52
def self.electronic_addresses(addr_list, xml)
return if addr_list.nil? or addr_list.empty?
addr_list.each do |addr|
xml.electronic_(:type => addr[:type]) do
xml.value_ addr[:value]
if addr.has_key?(:args)
addr[:args].each do |arg|
xml.arg_(arg[:value], :required => arg[:required], :type => arg[:type], :use => arg[:use])
end
end
end
end
end
|
.existence_dates(list, xml) ⇒ Object
153
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/rif-cs.rb', line 153
def self.existence_dates(list, xml)
return if list.nil? or list.empty?
list.each do |dates|
xml.existenceDates_ do
[:start_date, :end_date].each do |datetype|
date_obj = dates[datetype]
next if date_obj.nil?
xml.send(camelize(datetype), date_obj[:value], :dateFormat => date_obj[:date_format])
end
end
end
end
|
.list_of(list, name, xml) ⇒ Object
12
13
14
15
16
17
18
19
|
# File 'lib/rif-cs.rb', line 12
def self.list_of(list, name, xml)
list.each do |attrs|
xml.send(camelize(name), attrs[:value], attrs.select{|k| k != :value})
end
end
|
.locations(list, xml) ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/rif-cs.rb', line 32
def self.locations(list, xml)
return if list.nil? or list.empty?
list.each do |location|
xml.location_(:dateFrom => location[:date_from], :dateTo => location[:date_to], :type => location[:type]) do
addresses(location[:addresses], xml)
spatials(location[:spatials], xml)
end
end
end
|
.names(list, xml) ⇒ Object
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/rif-cs.rb', line 21
def self.names(list, xml)
return if list.nil? or list.empty?
list.each do |name|
xml.name_(:dateFrom => name[:date_from], :dateTo => name[:date_to], :type => name[:type], 'xml:lang' => name[:xmllang]) do
name[:name_parts].each do |part|
xml.namePart_(part[:value], :type => part[:type])
end
end
end
end
|
.physical_addresses(addr_list, xml) ⇒ Object
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/rif-cs.rb', line 66
def self.physical_addresses(addr_list, xml)
return if addr_list.nil? or addr_list.empty?
addr_list.each do |addr|
xml.physical_(:type => addr[:type], 'xml:lang' => addr[:xmllang]) do
addr[:address_parts].each do |addr_part|
xml.addressPart_(addr_part[:value], :type => addr_part[:type])
end
end
end
end
|
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/rif-cs.rb', line 124
def self.related_info(list, xml)
return if list.nil? or list.empty?
list.each do |info|
xml.relatedInfo_(:type => info[:type]) do
xml.identifier_(info[:identifier][:value], :type => info[:identifier][:type])
xml.title_(info[:title]) if info.has_key?(:title)
xml.notes(info[:notes]) if info.has_key?(:notes)
end
end
end
|
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/rif-cs.rb', line 108
def self.related_objects(obj, xml)
return if obj.nil?
obj.each do |rel_type, relations|
relations.each do |rel|
xml.relatedObject do
xml.key(rel[:key])
xml.relation_(:type => camelize(rel_type)) do
rel[:relation].each do |key, value|
xml.send(key, value)
end if rel.has_key?(:relation)
end
end
end
end
end
|
.rights(list, xml) ⇒ Object
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/rif-cs.rb', line 135
def self.rights(list, xml)
return if list.nil? or list.empty?
list.each do |rights|
xml.rights_ do
xml.rightsStatement_(rights[:rights_statement][:value], :rightsUri => rights[:rights_statement][:rights_uri]) if rights.has_key?(:rights_statement)
xml.licence_(rights[:licence][:value], :rightsUri => rights[:licence][:rights_uri]) if rights.has_key?(:licence)
xml.accessRights_(rights[:access_rights][:value], :rightsUri => rights[:access_rights][:rights_uri]) if rights.has_key?(:access_rights)
end
end
end
|
.spatials(spatial_list, xml) ⇒ Object
87
88
89
90
91
92
|
# File 'lib/rif-cs.rb', line 87
def self.spatials(spatial_list, xml)
return if spatial_list.nil? or spatial_list.empty?
spatial_list.each do |addr|
xml.spatial_(addr[:value], :type => addr[:type], 'xml:lang' => addr[:xmllang])
end
end
|
.subjects(list, xml) ⇒ Object
146
147
148
149
150
151
|
# File 'lib/rif-cs.rb', line 146
def self.subjects(list, xml)
return if list.nil? or list.empty?
list.each do |subject|
xml.subject_(subject[:value], :termIdentifier => subject[:term_identifier], :type => subject[:type], 'xml:lang' => subject[:xmllang])
end
end
|
.temporals(temp_list, xml) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/rif-cs.rb', line 94
def self.temporals(temp_list, xml)
return if temp_list.nil? or temp_list.empty?
temp_list.each do |temp|
xml.temporal_ do
temp[:dates].each do |date_elem|
xml.date_(date_elem[:value], :dateFormat => date_elem[:date_format], :type => date_elem[:type])
end
temp[:text].each do |text|
xml.text_ text
end
end
end
end
|
Instance Method Details
#to_rif(encoding = 'UTF-8') ⇒ Object
166
167
168
169
170
171
172
173
174
175
176
|
# File 'lib/rif-cs.rb', line 166
def to_rif(encoding='UTF-8')
reg_obj = to_registry_node
doc = Nokogiri::XML::Document.new
doc.encoding = encoding
container = Nokogiri::XML::Node.new('registryObjects', doc)
container['xsi:schemaLocation'] = 'http://ands.org.au/standards/rif-cs/registryObjects http://services.ands.org.au/documentation/rifcs/1.3/schema/registryObjects.xsd'
doc.root = container
reg_elems = reg_obj.doc.root.dup
container.add_child(reg_elems)
doc.root.to_xml
end
|