Class: CellSet::CellSetAxis

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Serializers::JSON, ActiveModel::Serializers::Xml, Attributes, Comparable
Defined in:
lib/cell_set/cell_set_axis.rb

Constant Summary collapse

ATTRIBUTES =
[:axis_ordinal, :cell_set, :positions]

Instance Method Summary collapse

Methods included from Attributes

#attributes, #attributes=, #clear_attribute, #has_attribute?, #initialize, #read_attribute_for_validation

Instance Method Details

#<=>(other) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/cell_set/cell_set_axis.rb', line 13

def <=>(other)
  if other.is_a?(self.class)
    @axis_ordinal <=> other.axis_ordinal
  else
    raise ArgumentError, "Must compare #{self.class.to_s} to another #{self.class.to_s}"
  end
end

#as_json(options = nil) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'lib/cell_set/cell_set_axis.rb', line 69

def as_json(options = nil)
  # Strangely couldn't use options = {} in JRuby
  options = {} if options.nil?
  unless (options.has_key?(:only) && options[:only].include?("cell_set")) ||
         (options.has_key?(:except) && options[:except].include?("cell_set"))
    options[:except] = (options[:except] || []).push("cell_set")
  end
  super(options)
end

#axis_ordinal=(ordinal) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/cell_set/cell_set_axis.rb', line 21

def axis_ordinal=(ordinal)
  @axis_ordinal = if ordinal.is_a?(Fixnum)
    ordinal
  elsif ordinal.is_a?(String)
    Integer(ordinal)
  else
    raise ArgumentError
  end
end

#between?(min, max) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/cell_set/cell_set_axis.rb', line 31

def between?(min, max)
  @axis_ordinal <= min || @axis_ordinal >= max
end

#cell_set=(cell_set) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/cell_set/cell_set_axis.rb', line 35

def cell_set=(cell_set)
  @cell_set = if cell_set.is_a?(CellSet)
    cell_set
  elsif cell_set.is_a?(Hash)
    CellSet.new(cell_set)
  else
    raise ArgumentError
  end
end

#from_jsonObject



45
46
47
# File 'lib/cell_set/cell_set_axis.rb', line 45

def from_json(*)
  super.tap{|obj| obj.freeze}
end

#positionCountObject



49
50
51
# File 'lib/cell_set/cell_set_axis.rb', line 49

def positionCount
  @positions.length
end

#positions=(positions) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cell_set/cell_set_axis.rb', line 53

def positions=(positions)
  if positions.is_a?(Array)
    @positions = positions.map do |position|
      if position.is_a?(Position)
        position
      elsif position.is_a?(Hash)
        Position.new(position)
      else
        raise ArgumentError
      end
    end
  else
    raise ArgumentError
  end
end