require 'cell_set/member' module CellSet class Position ATTRIBUTES = [:members, :ordinal] include Attributes include ActiveModel::Serializers::JSON include ActiveModel::Serializers::Xml include Comparable self.include_root_in_json = false def <=>(other) if other.is_a?(self.class) @ordinal <=> other.ordinal else nil end end def between?(min, max) @ordinal <= min || @ordinal >= max end def from_json(*) super.tap{|obj| obj.freeze} end def initialize(*) @members = [] super end def members=(members) if members.is_a?(Array) @members = members.map do |member| if member.is_a?(Member) member elsif member.is_a?(Hash) Member.new(member) else raise ArgumentError end end else raise ArgumentError end end def ordinal=(ordinal) @ordinal = if ordinal.is_a?(Fixnum) ordinal elsif ordinal.is_a?(String) Integer(ordinal) else raise ArgumentError end end end end