class DiamondLang::Helpers::Coordinate

Attributes

axis[R]

Public Class Methods

new(axis, v, relative=v.is_a?(String)&&v.include?('~')) click to toggle source
# File lib/diamond-lang/helpers/coordinate.rb, line 5
def initialize(axis, v, relative=v.is_a?(String)&&v.include?('~'))
  raise Errors::InvalidAxis.new(axis) unless Constants::Axes.include? (axis = axis.to_s.downcase)
  @axis = axis
  self.value=(v)
  @relative = relative
end

Public Instance Methods

+(amount) click to toggle source
# File lib/diamond-lang/helpers/coordinate.rb, line 21
def +(amount)
  @value += amount
end
-(amount) click to toggle source
# File lib/diamond-lang/helpers/coordinate.rb, line 24
def -(amount)
  @value -= amount
end
_value() click to toggle source
# File lib/diamond-lang/helpers/coordinate.rb, line 30
def _value
  @value
end
_value=(value) click to toggle source
# File lib/diamond-lang/helpers/coordinate.rb, line 27
def _value=(value)
  @value = value
end
inspect() click to toggle source
# File lib/diamond-lang/helpers/coordinate.rb, line 41
def inspect
  "#{self.class.to_s}(" + @axis + ": " + value + ")"
end
to_arg() click to toggle source
# File lib/diamond-lang/helpers/coordinate.rb, line 37
def to_arg
  raise Errors::RelativeCordinateConvertedToArgument if @relative
  "#{@axis}=#{@value}".freeze
end
to_s()
Alias for: value
value() click to toggle source
# File lib/diamond-lang/helpers/coordinate.rb, line 33
def value
  (@relative ? '~' : '') + @value.to_s
end
Also aliased as: to_s
value=(value) click to toggle source
# File lib/diamond-lang/helpers/coordinate.rb, line 11
def value=(value)
  @value = if value.is_a? Integer
    value
  elsif value.is_a?(String) && /^(?<rel>~)?(?<number>-?\d+)?$/ =~ value
    @relative = rel
    number.to_i
  else
    raise Errors::InvalidCoordinateValue.new value
  end
end