Class: Activerecord::Multirange::OID::MultiRange

Inherits:
ActiveModel::Type::Value
  • Object
show all
Defined in:
lib/activerecord-multirange/oid/multi_range.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Data

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#subtypeObject (readonly)

Returns the value of attribute subtype.



11
12
13
# File 'lib/activerecord-multirange/oid/multi_range.rb', line 11

def subtype
  @subtype
end

#typeObject (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

Returns:

  • (Boolean)


52
53
54
# File 'lib/activerecord-multirange/oid/multi_range.rb', line 52

def force_equality?(value)
  value.is_a?(::Array)
end

#serialize(value) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/activerecord-multirange/oid/multi_range.rb', line 29

def serialize(value)
  if value.is_a?(::Array)
    Data.new(type_cast_ranges(value, :serialize))
  else
    super
  end
end