Class: RasterValue

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming
Includes:
ActiveModel::Conversion, ActiveModel::Validations
Defined in:
app/models/raster_value.rb

Overview

RasterValue

provides a non-ActiveRecord-based class to hold the results of a call
to the terrapop_raster_summary() stored proc.

Code based on asciicasts.com/episodes/219-active-model and www.deploymentzone.com/2012/04/09/postgres-table-value-functions-and-rails-3/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(r) ⇒ RasterValue

Returns a new instance of RasterValue.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/models/raster_value.rb', line 16

def initialize(r)
  
  @sample_geog_level_id         = r.sample_geog_level_id
  @raster_variable_id           = r.raster_variable_id
  @raster_operation_name        = r.raster_operation_name
  @geog_instance_id             = r.geog_instance_id
  @internal_geog_instance_label = r.geog_instance_label
  @internal_geog_instance_code  = r.geog_instance_code
  @raster_mnemonic              = r.raster_mnemonic
  @boundary_area                = r.has_area_reference ? r.raster_area : r.boundary_area
  @summary_value                = r.summary_value
  @geog_instance                = r.geog_instance
  @raster_band_idx              = r.band_index
  @raster_dataset               = RasterDataset.find(r.raster_dataset_id)
  
  if @geog_instance.nil?
    raise "Must supply a geog_instance when creating a RasterValue"
  end
end

Instance Attribute Details

#boundary_areaObject (readonly)

Returns the value of attribute boundary_area.



14
15
16
# File 'app/models/raster_value.rb', line 14

def boundary_area
  @boundary_area
end

#geog_instanceObject (readonly)

Returns the value of attribute geog_instance.



14
15
16
# File 'app/models/raster_value.rb', line 14

def geog_instance
  @geog_instance
end

#geog_instance_idObject (readonly)

Returns the value of attribute geog_instance_id.



13
14
15
# File 'app/models/raster_value.rb', line 13

def geog_instance_id
  @geog_instance_id
end

#raster_mnemonicObject (readonly)

Returns the value of attribute raster_mnemonic.



14
15
16
# File 'app/models/raster_value.rb', line 14

def raster_mnemonic
  @raster_mnemonic
end

#raster_operation_nameObject (readonly)

Returns the value of attribute raster_operation_name.



13
14
15
# File 'app/models/raster_value.rb', line 13

def raster_operation_name
  @raster_operation_name
end

#raster_variable_idObject (readonly)

Returns the value of attribute raster_variable_id.



13
14
15
# File 'app/models/raster_value.rb', line 13

def raster_variable_id
  @raster_variable_id
end

#sample_geog_level_idObject (readonly)

Returns the value of attribute sample_geog_level_id.



13
14
15
# File 'app/models/raster_value.rb', line 13

def sample_geog_level_id
  @sample_geog_level_id
end

#summary_valueObject (readonly)

Returns the value of attribute summary_value.



14
15
16
# File 'app/models/raster_value.rb', line 14

def summary_value
  @summary_value
end

Instance Method Details

#construct_synthetic_mnemonicObject



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/models/raster_value.rb', line 56

def construct_synthetic_mnemonic
  #sample_geog_level = SampleGeogLevel.find(sample_geog_level_id)
  #geog_level_name = ""
  
  #unless sample_geog_level.geolink_variable.nil?
  #  geog_level_name = sample_geog_level.geolink_variable.mnemonic
  #else
  #  geog_level_name = sample_geog_level.country_level.country.short_name.upcase + "_" + sample_geog_level.country_level.geog_unit.code
  #end
  
  #"#{@raster_mnemonic}_#{geog_level_name}"
  @raster_mnemonic
end

#geog_instance_codeObject



44
45
46
# File 'app/models/raster_value.rb', line 44

def geog_instance_code
  geog_instance.code
end

#geog_instance_labelObject



48
49
50
# File 'app/models/raster_value.rb', line 48

def geog_instance_label
  geog_instance.label
end

#mnemonicObject



70
71
72
# File 'app/models/raster_value.rb', line 70

def mnemonic
  @raster_mnemonic
end

#mnemonic_symObject



74
75
76
# File 'app/models/raster_value.rb', line 74

def mnemonic_sym
  @raster_mnemonic.to_sym
end

#persisted?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/models/raster_value.rb', line 36

def persisted?  
  false
end

#to_sObject



78
79
80
# File 'app/models/raster_value.rb', line 78

def to_s
  value.nil? ? "<not set>" : @raster_mnemonic + ": #{value}"
end

#valueObject



40
41
42
# File 'app/models/raster_value.rb', line 40

def value
  @summary_value
end