Class: RGovData::Catalog
- Inherits:
-
Object
- Object
- RGovData::Catalog
- Includes:
- Dn
- Defined in:
- lib/rgovdata/catalog/catalog.rb
Instance Attribute Summary collapse
-
#realm ⇒ Object
Returns the value of attribute realm.
Class Method Summary collapse
-
.get(key) ⇒ Object
Returns the object specified by the
key
Key specification: //<realm>/<service-key>/<data-set-name> All key components are optional - you will get the best matching object for the key spec //sg - will return RGovData::Catalog for realm=:sg //sg/nlb - will return RGovData::ServiceListing for the nlb service in SG /nlb - will return RGovData::ServiceListing for the nlb service in SG (assuming SG is the default realm) //sg/nlb/Library - will return RGovData::OdataService for the nlb Library service in SG.
Instance Method Summary collapse
-
#get_service(key) ⇒ Object
Returns the service(s) matching
key
. -
#initialize(default_realm = nil) ⇒ Catalog
constructor
A new instance of Catalog.
-
#realms ⇒ Object
Returns available realms.
-
#records ⇒ Object
Generic interface to return the currently applicable record set => overrides RGovData::Dn.records.
-
#services ⇒ Object
Returns an array of ServiceListings for the current realm.
Methods included from Dn
#attributes, #id, #initialization_hash, #meta_attributes, #to_param, #to_s
Constructor Details
#initialize(default_realm = nil) ⇒ Catalog
Returns a new instance of Catalog.
29 30 31 |
# File 'lib/rgovdata/catalog/catalog.rb', line 29 def initialize(default_realm=nil) @realm = default_realm && default_realm.to_sym end |
Instance Attribute Details
#realm ⇒ Object
Returns the value of attribute realm.
2 3 4 |
# File 'lib/rgovdata/catalog/catalog.rb', line 2 def realm @realm end |
Class Method Details
.get(key) ⇒ Object
Returns the object specified by the key
Key specification: //<realm>/<service-key>/<data-set-name> All key components are optional - you will get the best matching object for the key spec //sg - will return RGovData::Catalog for realm=:sg //sg/nlb - will return RGovData::ServiceListing for the nlb service in SG /nlb - will return RGovData::ServiceListing for the nlb service in SG (assuming SG is the default realm) //sg/nlb/Library - will return RGovData::OdataService for the nlb Library service in SG
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rgovdata/catalog/catalog.rb', line 14 def get(key) key ||= '//' key.gsub!(':','/') # handle alternate encoding keypart = Regexp.new(/(?:\/\/([^\/]+))?(?:\/([^\/]+))?(?:\/([^\/]+))?/).match(key) found = catalog = self.new(keypart[1]) if keypart[2] found = service = catalog.get_service(keypart[2]) if keypart[3] found = service.get_dataset(keypart[3]) end end found end |
Instance Method Details
#get_service(key) ⇒ Object
Returns the service(s) matching key
45 46 47 48 49 |
# File 'lib/rgovdata/catalog/catalog.rb', line 45 def get_service(key) return nil unless services && !services.empty? matches = services.select {|s| s.key =~ /#{key}/} matches.count == 1 ? matches.first : matches end |
#realms ⇒ Object
Returns available realms
34 35 36 37 |
# File 'lib/rgovdata/catalog/catalog.rb', line 34 def realms # TODO: currently hard-coded [:sg,:us].map{|realm| self.class.new(realm) } end |
#records ⇒ Object
Generic interface to return the currently applicable record set
> overrides RGovData::Dn.records
65 66 67 68 69 70 71 |
# File 'lib/rgovdata/catalog/catalog.rb', line 65 def records if realm.present? services else realms end end |
#services ⇒ Object
Returns an array of ServiceListings for the current realm
40 41 42 |
# File 'lib/rgovdata/catalog/catalog.rb', line 40 def services @services ||= registry_strategy.load_services end |