Class: Activerecord::Multirange::OID::MultiRange
- Inherits:
-
ActiveModel::Type::Value
- Object
- ActiveModel::Type::Value
- Activerecord::Multirange::OID::MultiRange
- Defined in:
- lib/activerecord-multirange/oid/multi_range.rb
Overview
:nodoc:
Defined Under Namespace
Classes: Data
Instance Attribute Summary collapse
-
#subtype ⇒ Object
readonly
Returns the value of attribute subtype.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #cast_value(value) ⇒ Object
- #deserialize(value) ⇒ Object
- #force_equality?(value) ⇒ Boolean
-
#initialize(subtype, type = :multirange) ⇒ MultiRange
constructor
A new instance of MultiRange.
- #serialize(value) ⇒ Object
Constructor Details
#initialize(subtype, type = :multirange) ⇒ MultiRange
Returns a new instance of MultiRange.
13 14 15 16 17 18 |
# File 'lib/activerecord-multirange/oid/multi_range.rb', line 13 def initialize(subtype, type = :multirange) @subtype = subtype @type = type super() end |
Instance Attribute Details
#subtype ⇒ Object (readonly)
Returns the value of attribute subtype.
11 12 13 |
# File 'lib/activerecord-multirange/oid/multi_range.rb', line 11 def subtype @subtype end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
11 12 13 |
# File 'lib/activerecord-multirange/oid/multi_range.rb', line 11 def type @type end |
Instance Method Details
#==(other) ⇒ Object
46 47 48 49 50 |
# File 'lib/activerecord-multirange/oid/multi_range.rb', line 46 def ==(other) other.is_a?(MultiRange) && other.subtype == subtype && other.type == type end |
#cast_value(value) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/activerecord-multirange/oid/multi_range.rb', line 37 def cast_value(value) return nil if value.blank? return value unless value.is_a?(::String) ranges = scan_ranges(value) ranges.map { |r| build_range(r) } end |
#deserialize(value) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/activerecord-multirange/oid/multi_range.rb', line 20 def deserialize(value) case value when ::String cast_value(value) when Data type_cast_ranges(value.ranges, :deserialize) end end |
#force_equality?(value) ⇒ Boolean
52 53 54 |
# File 'lib/activerecord-multirange/oid/multi_range.rb', line 52 def force_equality?(value) value.is_a?(::Array) end |