Class: DataMapper::Property::PgNumericArray

Inherits:
PgArray
  • Object
show all
Defined in:
lib/dm-postgres-types/property/pg_numeric_array.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from PgArray

#dump

Constructor Details

#initialize(model, name, options = {}) ⇒ PgNumericArray

Returns a new instance of PgNumericArray.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dm-postgres-types/property/pg_numeric_array.rb', line 12

def initialize(model, name, options = {})
  super
  @precision = @options[:precision] || 10
  @scale     = @options[:scale]     || 0

  if precision <= 0
    raise ArgumentError, "precision must be greater than 0"
  end

  if scale <= 0
    raise ArgumentError, "scale must be greater than or equal to 0"
  end        
end

Instance Attribute Details

#precisionObject (readonly)

Returns the value of attribute precision.



10
11
12
# File 'lib/dm-postgres-types/property/pg_numeric_array.rb', line 10

def precision
  @precision
end

#scaleObject (readonly)

Returns the value of attribute scale.



10
11
12
# File 'lib/dm-postgres-types/property/pg_numeric_array.rb', line 10

def scale
  @scale
end

Instance Method Details

#load(value) ⇒ Object



26
27
28
29
30
# File 'lib/dm-postgres-types/property/pg_numeric_array.rb', line 26

def load(value)
  values = super
  values.map! { |val| (scale > 0) ? val.to_f : val.to_i } if values
  values
end