Class: DiamondLang::Helpers::Coordinate
- Defined in:
- lib/diamond-lang/helpers/coordinate.rb
Instance Attribute Summary collapse
-
#axis ⇒ Object
readonly
Returns the value of attribute axis.
Instance Method Summary collapse
- #+(amount) ⇒ Object
- #-(amount) ⇒ Object
- #_value ⇒ Object
- #_value=(value) ⇒ Object
-
#initialize(axis, v, relative = v.is_a?(String)&&v.include?('~')) ⇒ Coordinate
constructor
A new instance of Coordinate.
- #inspect ⇒ Object
- #to_arg ⇒ Object
- #value ⇒ Object (also: #to_s)
- #value=(value) ⇒ Object
Constructor Details
#initialize(axis, v, relative = v.is_a?(String)&&v.include?('~')) ⇒ Coordinate
Returns a new instance of Coordinate.
5 6 7 8 9 10 |
# 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 |
Instance Attribute Details
#axis ⇒ Object (readonly)
Returns the value of attribute axis.
4 5 6 |
# File 'lib/diamond-lang/helpers/coordinate.rb', line 4 def axis @axis end |
Instance Method Details
#+(amount) ⇒ Object
21 22 23 |
# File 'lib/diamond-lang/helpers/coordinate.rb', line 21 def +(amount) @value += amount end |
#-(amount) ⇒ Object
24 25 26 |
# File 'lib/diamond-lang/helpers/coordinate.rb', line 24 def -(amount) @value -= amount end |
#_value ⇒ Object
30 31 32 |
# File 'lib/diamond-lang/helpers/coordinate.rb', line 30 def _value @value end |
#_value=(value) ⇒ Object
27 28 29 |
# File 'lib/diamond-lang/helpers/coordinate.rb', line 27 def _value=(value) @value = value end |
#inspect ⇒ Object
41 42 43 |
# File 'lib/diamond-lang/helpers/coordinate.rb', line 41 def inspect "#{self.class.to_s}(" + @axis + ": " + value + ")" end |
#to_arg ⇒ Object
37 38 39 40 |
# File 'lib/diamond-lang/helpers/coordinate.rb', line 37 def to_arg raise Errors::RelativeCordinateConvertedToArgument if @relative "#{@axis}=#{@value}".freeze end |
#value ⇒ Object Also known as: to_s
33 34 35 |
# File 'lib/diamond-lang/helpers/coordinate.rb', line 33 def value (@relative ? '~' : '') + @value.to_s end |
#value=(value) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# 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 |