Class: DataMapper::Property::PgNumericArray
- Defined in:
- lib/dm-postgres-types/property/pg_numeric_array.rb
Instance Attribute Summary collapse
-
#precision ⇒ Object
readonly
Returns the value of attribute precision.
-
#scale ⇒ Object
readonly
Returns the value of attribute scale.
Instance Method Summary collapse
-
#initialize(model, name, options = {}) ⇒ PgNumericArray
constructor
A new instance of PgNumericArray.
- #load(value) ⇒ Object
Methods inherited from PgArray
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, = {}) 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
#precision ⇒ Object (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 |
#scale ⇒ Object (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 |