Class: SimpleRecord::Attributes::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_record/attributes.rb

Overview

Holds information about an attribute

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, options = nil) ⇒ Attribute

Returns a new instance of Attribute.



411
412
413
414
# File 'lib/simple_record/attributes.rb', line 411

def initialize(type, options=nil)
    @type    = type
    @options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



409
410
411
# File 'lib/simple_record/attributes.rb', line 409

def options
  @options
end

#typeObject

Returns the value of attribute type.



409
410
411
# File 'lib/simple_record/attributes.rb', line 409

def type
  @type
end

Instance Method Details

#init_value(value) ⇒ Object



416
417
418
419
420
421
422
423
424
425
426
427
428
# File 'lib/simple_record/attributes.rb', line 416

def init_value(value)
    return value if value.nil?
    ret = value
    case self.type
        when :int
            if value.is_a? Array
                ret = value.collect { |x| x.to_i }
            else
                ret = value.to_i
            end
    end
    ret
end