Class: RGovData::DataSet

Inherits:
Object
  • Object
show all
Includes:
Dn
Defined in:
lib/rgovdata/service/dataset/dataset.rb

Overview

This is the catalog class that describes a generic Service DataSet

Direct Known Subclasses

FileDataSet, OdataDataSet

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Dn

#attributes, #id, #initialization_hash, #to_param, #to_s

Constructor Details

#initialize(options, service) ⇒ DataSet

Returns a new instance of DataSet.



19
20
21
22
23
24
25
26
27
# File 'lib/rgovdata/service/dataset/dataset.rb', line 19

def initialize(options,service)
  @options = if options.is_a?(Hash)
    OpenStruct.new(options)
  else
    OpenStruct.new
  end
  @service = service.dup # avoid circular dependencies
  @native_service = @service.try(:native_instance)
end

Instance Attribute Details

#native_serviceObject (readonly)

Returns the value of attribute native_service.



6
7
8
# File 'lib/rgovdata/service/dataset/dataset.rb', line 6

def native_service
  @native_service
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/rgovdata/service/dataset/dataset.rb', line 4

def options
  @options
end

#serviceObject (readonly)

Returns the value of attribute service.



5
6
7
# File 'lib/rgovdata/service/dataset/dataset.rb', line 5

def service
  @service
end

Class Method Details

.load_datasets(service) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/rgovdata/service/dataset/dataset.rb', line 9

def load_datasets(service)
  dataset_class = "RGovData::#{service.type.to_s.capitalize}DataSet".constantize
  ds = []
  service.dataset_keys.each do |dataset|
    ds << dataset_class.new({:dataset_key=>dataset},service)
  end
  ds
end

Instance Method Details

#attribute_value(row, attribute) ⇒ Object

Returns the value of the named attribute from a recordset row Purpose is to encapsulate differences in addressing attribute values



72
73
74
# File 'lib/rgovdata/service/dataset/dataset.rb', line 72

def attribute_value(row,attribute)
  row.send(attribute)
end

#dataset_keyObject Also known as: native_dataset_key



32
# File 'lib/rgovdata/service/dataset/dataset.rb', line 32

def dataset_key     ; options.dataset_key         ; end

#limitObject

Returns the record limit currently imposed



35
# File 'lib/rgovdata/service/dataset/dataset.rb', line 35

def limit           ; options.limit               ; end

#limit=(value) ⇒ Object

Set the record limit to value



37
38
39
# File 'lib/rgovdata/service/dataset/dataset.rb', line 37

def limit=(value)
  options.limit = value
end

#meta_attributesObject

Returns array of attributes that describe the specific entity

> overrides RGovData::Dn.meta_attributes



43
44
45
# File 'lib/rgovdata/service/dataset/dataset.rb', line 43

def meta_attributes
  [:id,:realm,:service_key,:dataset_key]
end

#native_instance(reload = false) ⇒ Object

Returns the native dataset instance If reload is true, it re-initializes



52
53
54
55
56
57
58
# File 'lib/rgovdata/service/dataset/dataset.rb', line 52

def native_instance(reload = false)
  @native_instance = if reload
    load_instance
  else
    @native_instance || load_instance
  end
end

#realmObject

attribute accessors



30
# File 'lib/rgovdata/service/dataset/dataset.rb', line 30

def realm           ; service.realm               ; end

#records(reload = false) ⇒ Object

Returns the records If reload is true, it re-initializes and re-runs the query



62
63
64
65
66
67
68
# File 'lib/rgovdata/service/dataset/dataset.rb', line 62

def records(reload = false)
  @records = if reload
    load_records
  else
    @records || load_records
  end
end

#service_keyObject



31
# File 'lib/rgovdata/service/dataset/dataset.rb', line 31

def service_key     ; service.service_key         ; end

#uriObject



33
# File 'lib/rgovdata/service/dataset/dataset.rb', line 33

def uri             ; service.uri                 ; end