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
-
#attributes ⇒ Object
Returns array of attributes that describe the records of the specific entity By default, it is nil (meaning indeterminate).
-
#id ⇒ Object
Returns the human-readable unique id.
-
#initialization_hash ⇒ Object
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. -
#meta_attributes ⇒ Object
Returns array of attributes that describe the specific entity By default, guesses based on instance variables.
-
#records ⇒ Object
Generic interface to return the currently applicable record set.
-
#to_param ⇒ Object
Returns a rails-compatible ID.
-
#to_s ⇒ Object
Returns the human version of the object name/identification.
Instance Method Details
#attributes ⇒ Object
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 |
#id ⇒ Object
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_hash ⇒ Object
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 = {} .each do |attribute| h.merge!(attribute => self.send(attribute)) end h end |
#meta_attributes ⇒ Object
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 a = [:id] instance_variables.each do |v| n = v.to_s.gsub('@','').to_sym a << n if self.respond_to?(n) end a end |
#records ⇒ Object
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_param ⇒ Object
Returns a rails-compatible ID
18 19 20 |
# File 'lib/rgovdata/catalog/dn.rb', line 18 def to_param id.gsub('/',':') end |
#to_s ⇒ Object
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 |