rif-cs 1.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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'nokogiri'
4
+
5
+ group :development do
6
+ gem "rspec"
7
+ gem "rdoc"
8
+ gem "bundler", "~> 1.1.0"
9
+ gem "jeweler", "~> 1.8.3"
10
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,33 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ git (1.2.5)
6
+ jeweler (1.8.3)
7
+ bundler (~> 1.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rdoc
11
+ json (1.7.3)
12
+ nokogiri (1.5.3)
13
+ rake (0.9.2.2)
14
+ rdoc (3.12)
15
+ json (~> 1.4)
16
+ rspec (2.10.0)
17
+ rspec-core (~> 2.10.0)
18
+ rspec-expectations (~> 2.10.0)
19
+ rspec-mocks (~> 2.10.0)
20
+ rspec-core (2.10.1)
21
+ rspec-expectations (2.10.0)
22
+ diff-lcs (~> 1.1.3)
23
+ rspec-mocks (2.10.1)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.1.0)
30
+ jeweler (~> 1.8.3)
31
+ nokogiri
32
+ rdoc
33
+ rspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Sean McCarthy
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,9 @@
1
+ = ruby_rif-cs
2
+
3
+ A module to help generate {RIF-CS}[http://ands.org.au/resource/rif-cs.html]
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2012 Intersect Australia Ltd. See LICENSE.txt for
8
+ further details.
9
+
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "rif-cs"
18
+ gem.homepage = "http://github.com/IntersectAustralia/ruby_rif-cs"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Instrument your class to return RIF-CS}
21
+ gem.description = %Q{Instrument your class to return RIF-CS}
22
+ gem.email = "sean@intersect.org.au"
23
+ gem.authors = ["Sean McCarthy"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "RIF-CS (for Ruby) #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
data/lib/rif-cs.rb ADDED
@@ -0,0 +1,167 @@
1
+ require 'rif-cs/party'
2
+ require 'rif-cs/service'
3
+ require 'rif-cs/collection'
4
+ require 'rif-cs/activity'
5
+
6
+ module RIFCS
7
+
8
+ def self.camelize(lower_case_and_underscored_word)
9
+ lower_case_and_underscored_word.to_s.gsub(/(?:_)(.)/) { $1.upcase }
10
+ end
11
+
12
+ def self.list_of(list, name, xml)
13
+ #method_name = "#{prefix}_#{name}"
14
+ #return unless respond_to?(method_name.to_sym)
15
+ #puts list.inspect
16
+ list.each do |attrs|
17
+ xml.send(camelize(name), attrs[:value], attrs.select{|k| k != :value})
18
+ end
19
+ end
20
+
21
+ def self.names(list, xml)
22
+ return if list.nil? or list.empty?
23
+ list.each do |name|
24
+ xml.name_(:dateFrom => name[:date_from], :dateTo => name[:date_to], :type => name[:type], 'xml:lang' => name[:xmllang]) do
25
+ name[:name_parts].each do |part|
26
+ xml.namePart_(part[:value], :type => part[:type])
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ def self.locations(list, xml)
33
+ return if list.nil? or list.empty?
34
+ list.each do |location|
35
+ xml.location_(:dateFrom => location[:date_from], :dateTo => location[:date_to], :type => location[:type]) do
36
+ addresses(location[:addresses], xml)
37
+ spatials(location[:spatials], xml)
38
+ end
39
+ end
40
+ end
41
+
42
+ def self.addresses(addr_list, xml)
43
+ return if addr_list.nil? or addr_list.empty?
44
+ xml.address_ do
45
+ addr_list.each do |addr|
46
+ electronic_addresses(addr[:electronic], xml)
47
+ physical_addresses(addr[:physical], xml)
48
+ end
49
+ end
50
+ end
51
+
52
+ def self.electronic_addresses(addr_list, xml)
53
+ return if addr_list.nil? or addr_list.empty?
54
+ addr_list.each do |addr|
55
+ xml.electronic_(:type => addr[:type]) do
56
+ xml.value_ addr[:value]
57
+ if addr.has_key?(:args)
58
+ addr[:args].each do |arg|
59
+ xml.arg_(arg[:value], :required => arg[:required], :type => arg[:type], :use => arg[:use])
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ def self.physical_addresses(addr_list, xml)
67
+ return if addr_list.nil? or addr_list.empty?
68
+ addr_list.each do |addr|
69
+ xml.physical_(:type => addr[:type], 'xml:lang' => addr[:xmllang]) do
70
+ addr[:address_parts].each do |addr_part|
71
+ xml.addressPart_(addr_part[:value], :type => addr_part[:type])
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ def self.coverage(list, xml)
78
+ return if list.nil? or list.empty?
79
+ list.each do |coverage|
80
+ xml.coverage_ do
81
+ spatials(coverage[:spatials], xml)
82
+ temporals(coverage[:temporals], xml)
83
+ end
84
+ end
85
+ end
86
+
87
+ def self.spatials(spatial_list, xml)
88
+ return if spatial_list.nil? or spatial_list.empty?
89
+ spatial_list.each do |addr|
90
+ xml.spatial_(addr[:value], :type => addr[:type], 'xml:lang' => addr[:xmllang])
91
+ end
92
+ end
93
+
94
+ def self.temporals(temp_list, xml)
95
+ return if temp_list.nil? or temp_list.empty?
96
+ temp_list.each do |temp|
97
+ xml.temporal_ do
98
+ temp[:dates].each do |date_elem|
99
+ xml.date_(date_elem[:value], :dateFormat => date_elem[:date_format], :type => date_elem[:type])
100
+ end
101
+ temp[:text].each do |text|
102
+ xml.text_ text
103
+ end
104
+ end
105
+ end
106
+ end
107
+
108
+ def self.related_objects(obj, xml)
109
+ return if obj.nil?
110
+ obj.each do |rel_type, relations|
111
+ relations.each do |rel|
112
+ xml.relatedObject do
113
+ xml.key(rel[:key])
114
+ xml.relation_(:type => camelize(rel_type)) do
115
+ rel[:relation].each do |key, value|
116
+ xml.send(key, value)
117
+ end if rel.has_key?(:relation)
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
123
+
124
+ def self.related_info(list, xml)
125
+ return if list.nil? or list.empty?
126
+ list.each do |info|
127
+ xml.relatedInfo_(:type => info[:type]) do
128
+ xml.identifier_(info[:identifier][:value], :type => info[:identifier][:type])
129
+ xml.title_(info[:title]) if info.has_key?(:title)
130
+ xml.notes(info[:notes]) if info.has_key?(:notes)
131
+ end
132
+ end
133
+ end
134
+
135
+ def self.rights(list, xml)
136
+ return if list.nil? or list.empty?
137
+ list.each do |rights|
138
+ xml.rights_ do
139
+ xml.rightsStatement_(rights[:rights_statement][:value], :rightsUri => rights[:rights_statement][:rights_uri]) if rights.has_key?(:rights_statement)
140
+ xml.licence_(rights[:licence][:value], :rightsUri => rights[:licence][:rights_uri]) if rights.has_key?(:licence)
141
+ xml.accessRights_(rights[:access_rights][:value], :rightsUri => rights[:access_rights][:rights_uri]) if rights.has_key?(:access_rights)
142
+ end
143
+ end
144
+ end
145
+
146
+ def self.subjects(list, xml)
147
+ return if list.nil? or list.empty?
148
+ list.each do |subject|
149
+ xml.subject_(subject[:value], :termIdentifier => subject[:term_identifier], :type => subject[:type], 'xml:lang' => subject[:xmllang])
150
+ end
151
+ end
152
+
153
+ def self.existence_dates(list, xml)
154
+ return if list.nil? or list.empty?
155
+ list.each do |dates|
156
+ xml.existenceDates_ do
157
+ [:start_date, :end_date].each do |datetype|
158
+ date_obj = dates[datetype]
159
+ next if date_obj.nil?
160
+ xml.send(camelize(datetype), date_obj[:value], :dateFormat => date_obj[:date_format])
161
+ end
162
+ end
163
+ end
164
+ end
165
+
166
+ end
167
+
@@ -0,0 +1,45 @@
1
+ module RIFCS
2
+ module Activity
3
+ include RIFCS
4
+ require 'nokogiri'
5
+
6
+ def to_rifcs(encoding='UTF-8')
7
+ Nokogiri::XML::Builder.new(:encoding => encoding) do |xml|
8
+ xml.registryObject_(:group => activity_group) do
9
+
10
+ xml.key_ activity_key
11
+ xml.originatingSource_ activity_originating_source if respond_to?(:activity_originating_source)
12
+
13
+ xml.activity_(:dateModified => activity_date_modified, :type => activity_type) do
14
+ RIFCS::list_of(activity_identifiers, :identifiers, xml) if respond_to?(:activity_identifiers)
15
+
16
+ RIFCS::names(activity_names, xml) if respond_to?(:activity_names)
17
+
18
+ RIFCS::locations(activity_locations, xml) if respond_to?(:activity_locations)
19
+
20
+ RIFCS::coverage(activity_coverage, xml) if respond_to?(:activity_coverage)
21
+
22
+ RIFCS::list_of(activity_descriptions, :descriptions, xml) if respond_to?(:activity_descriptions)
23
+
24
+ RIFCS::existence_dates(activity_existence_dates, xml) if respond_to?(:activity_existence_dates)
25
+
26
+ RIFCS::related_info(activity_related_info, xml) if respond_to?(:activity_related_infos)
27
+
28
+ RIFCS::related_objects(activity_related_objects, xml) if respond_to?(:activity_related_objects)
29
+
30
+ RIFCS::rights(activity_rights, xml) if respond_to?(:activity_rights)
31
+
32
+ RIFCS::subjects(activity_subjects, xml) if respond_to?(:activity_subjects)
33
+
34
+ end # activity
35
+ end
36
+ end
37
+ end
38
+
39
+ def activity_key
40
+ raise "Supply a activity_key attribute or implement a method"
41
+ end
42
+
43
+
44
+ end
45
+ end
@@ -0,0 +1,74 @@
1
+ module RIFCS
2
+ module Collection
3
+ include RIFCS
4
+ require 'nokogiri'
5
+
6
+ def to_rifcs(encoding='UTF-8')
7
+ Nokogiri::XML::Builder.new(:encoding => encoding) do |xml|
8
+ xml.registryObject_(:group => collection_group) do
9
+
10
+ xml.key_ collection_key
11
+ xml.originatingSource_ collection_originating_source if respond_to?(:collection_originating_source)
12
+
13
+ xml.collection_(:dateModified => collection_date_modified, :type => collection_type, :dateAccessioned => collection_date_accessioned) do
14
+ RIFCS::list_of(collection_identifiers, :identifiers, xml) if respond_to?(:collection_identifiers)
15
+
16
+ RIFCS::names(collection_names, xml) if respond_to?(:collection_names)
17
+
18
+ RIFCS::locations(collection_locations, xml) if respond_to?(:collection_locations)
19
+
20
+ RIFCS::coverage(collection_coverage, xml) if respond_to?(:collection_coverage)
21
+
22
+ RIFCS::related_objects(collection_related_objects, xml) if respond_to?(:collection_related_objects)
23
+
24
+ RIFCS::subjects(collection_subjects, xml) if respond_to?(:collection_subjects)
25
+
26
+ RIFCS::list_of(collection_descriptions, :descriptions, xml) if respond_to?(:collection_descriptions)
27
+
28
+ RIFCS::rights(collection_rights, xml) if respond_to?(:collection_rights)
29
+
30
+ RIFCS::related_info(collection_related_info, xml) if respond_to?(:collection_related_infos)
31
+
32
+ citation_info(collection_citation_info, xml) if respond_to?(:collection_citation_info)
33
+ end # collection
34
+ end
35
+ end
36
+ end
37
+
38
+ def citation_info(list, xml)
39
+ return if list.nil? or list.empty?
40
+ list.each do |citation|
41
+ xml.fullCitation_(citation[:full_citation][:value], :style => citation[:full_citation][:style])
42
+ xml.citationMetadata_ do
43
+ meta_obj = citation[:citation_metadata]
44
+ xml.identifier(meta_obj[:identifier][:value], :type => meta_obj[:identifier][:type])
45
+ meta_obj[:contributor].each do |name|
46
+ xml.contributor_(:seq => name[:seq]) do
47
+ name[:name_parts].each do |part|
48
+ xml.namePart_(part[:value], :type => part[:type])
49
+ end
50
+ end
51
+ end
52
+ xml.title_(meta_obj[:title])
53
+ xml.edition_(meta_obj[:edition])
54
+ xml.publisher_(meta_obj[:publisher]) if meta_obj.has_key?(:publisher)
55
+ xml.placePublished_(meta_obj[:place_published])
56
+ meta_obj[:date].each do |d|
57
+ xml.date_(d[:value], :type => d[:type])
58
+ end if meta_obj.has_key?(:date)
59
+ xml.url_(meta_obj[:url])
60
+ xml.context_(meta_obj[:context])
61
+ end
62
+ end
63
+ end
64
+
65
+ def collection_key
66
+ raise "Supply a collection_key attribute or implement a method"
67
+ end
68
+
69
+
70
+ def collection_originating_source
71
+ raise "Supply a collection_originating_source attribute or implement a method"
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,45 @@
1
+ module RIFCS
2
+ module Party
3
+ include RIFCS
4
+ require 'nokogiri'
5
+
6
+ def to_rifcs(encoding='UTF-8')
7
+ Nokogiri::XML::Builder.new(:encoding => encoding) do |xml|
8
+ xml.registryObject_(:group => party_group) do
9
+
10
+ xml.key_ party_key
11
+ xml.originatingSource_ party_originating_source if respond_to?(:party_originating_source)
12
+
13
+ xml.party_(:dateModified => party_date_modified, :type => party_type) do
14
+ RIFCS::list_of(party_identifiers, :identifiers, xml) if respond_to?(:party_identifiers)
15
+
16
+ RIFCS::names(party_names, xml) if respond_to?(:party_names)
17
+
18
+ RIFCS::locations(party_locations, xml) if respond_to?(:party_locations)
19
+
20
+ RIFCS::coverage(party_coverage, xml) if respond_to?(:party_coverage)
21
+
22
+ RIFCS::list_of(party_descriptions, :descriptions, xml) if respond_to?(:party_descriptions)
23
+
24
+ RIFCS::existence_dates(party_existence_dates, xml) if respond_to?(:party_existence_dates)
25
+
26
+ RIFCS::related_info(party_related_info, xml) if respond_to?(:party_related_infos)
27
+
28
+ RIFCS::related_objects(party_related_objects, xml) if respond_to?(:party_related_objects)
29
+
30
+ RIFCS::rights(party_rights, xml) if respond_to?(:party_rights)
31
+
32
+ RIFCS::subjects(party_subjects, xml) if respond_to?(:party_subjects)
33
+
34
+ end # party
35
+ end
36
+ end
37
+ end
38
+
39
+ def party_key
40
+ raise "Supply a party_key attribute or implement a method"
41
+ end
42
+
43
+
44
+ end
45
+ end