Module: RGovData::Dn

Included in:
Catalog, DataSet, Service, ServiceListing
Defined in:
lib/rgovdata/catalog/dn.rb

Overview

This module defines the basic naming interface for catalog objects Override these methods as required

Instance Method Summary collapse

Instance Method Details

#attributesObject

Returns array of attributes that describe the records of the specific entity By default, it is nil (meaning indeterminate)



50
51
52
# File 'lib/rgovdata/catalog/dn.rb', line 50

def attributes
  @attributes
end

#idObject

Returns the human-readable unique id



6
7
8
9
10
11
12
13
14
15
# File 'lib/rgovdata/catalog/dn.rb', line 6

def id
  nameparts = []
  if defined? realm
    nameparts.push('/')
    nameparts.push(realm)
  end
  nameparts.push(service_key) if defined?(service_key) && service_key.present?
  nameparts.push(dataset_key) if defined?(dataset_key) && dataset_key.present?
  nameparts.join('/')
end

#initialization_hashObject

Returns a hash that fully describes this service and can be used as a parameter to new By default, returns a hash based on meta_attributes



40
41
42
43
44
45
46
# File 'lib/rgovdata/catalog/dn.rb', line 40

def initialization_hash
  h = {}
  meta_attributes.each do |attribute|
    h.merge!(attribute => self.send(attribute))
  end
  h
end

#meta_attributesObject

Returns array of attributes that describe the specific entity By default, guesses based on instance variables



29
30
31
32
33
34
35
36
# File 'lib/rgovdata/catalog/dn.rb', line 29

def meta_attributes
  a = [:id]
  instance_variables.each do |v|
    n = v.to_s.gsub('@','').to_sym
    a << n if self.respond_to?(n)
  end
  a
end

#recordsObject

Generic interface to return the currently applicable record set



55
56
57
58
59
60
61
# File 'lib/rgovdata/catalog/dn.rb', line 55

def records
  if defined? datasets
    datasets
  else
    []
  end
end

#to_paramObject

Returns a rails-compatible ID



18
19
20
# File 'lib/rgovdata/catalog/dn.rb', line 18

def to_param
  id.gsub('/',':')
end

#to_sObject

Returns the human version of the object name/identification



23
24
25
# File 'lib/rgovdata/catalog/dn.rb', line 23

def to_s
  "#{id} [#{self.class.name}]"
end