Class: SerializableAttributes::Boolean
- Inherits:
-
AttributeType
- Object
- AttributeType
- SerializableAttributes::Boolean
- Defined in:
- lib/serializable_attributes/types.rb
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
Instance Method Summary collapse
Methods inherited from AttributeType
Constructor Details
This class inherits a constructor from SerializableAttributes::AttributeType
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
29 30 31 |
# File 'lib/serializable_attributes/types.rb', line 29 def default @default end |
Instance Method Details
#encode(input) ⇒ Object
38 39 40 41 42 |
# File 'lib/serializable_attributes/types.rb', line 38 def encode(input) return nil if input.to_s.empty? return 0 if input == 'false' input ? 1 : 0 end |
#parse(input) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/serializable_attributes/types.rb', line 30 def parse(input) return nil if input == "" return true if input == 'true' return false if input == 'false' input && input.respond_to?(:to_i) ? (input.to_i > 0) : input end |