module RIFCS
Public Class Methods
addresses(addr_list, xml)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/rif-cs.rb, line 12 def self.list_of(list, name, xml) #method_name = "#{prefix}_#{name}" #return unless respond_to?(method_name.to_sym) #puts list.inspect list.each do |attrs| xml.send(camelize(name), attrs[:value], attrs.select{|k| k != :value}) end end
locations(list, xml)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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
rights(list, xml)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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
Public Instance Methods
to_rif(encoding='UTF-8')
click to toggle source
# 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