lib/triangular/point.rb in triangular-0.0.2 vs lib/triangular/point.rb in triangular-0.1.1

- old
+ new

@@ -1,39 +1,39 @@ +# frozen_string_literal: true + module Triangular class Point - attr_accessor :x, :y, :z - + def initialize(x, y, z) @x = x @y = y - @z = z + @z = z end - + def to_s "#{@x.to_f} #{@y.to_f} #{@z.to_f}" end - + def translate!(x, y, z) @x += x @y += y @z += z end - + def ==(other) return false unless other.is_a?(Point) - self.x == other.x && self.y == other.y && self.z == other.z + + x == other.x && y == other.y && z == other.z end - + def self.parse(string) - string.strip! - match_data = string.match(self.pattern) - - self.new(match_data[:x].to_f, match_data[:y].to_f, match_data[:z].to_f) + match_data = string.strip.match(pattern) + + new(match_data[:x].to_f, match_data[:y].to_f, match_data[:z].to_f) end - + def self.pattern - /(?<x>-?\d+.\d+(e\-?\d+)?)\s(?<y>-?\d+.\d+(e\-?\d+)?)\s(?<z>-?\d+.\d+(e\-?\d+)?)/ + /(?<x>-?\d+(.\d+(e-?\d+)?)?)\s(?<y>-?\d+(.\d+(e-?\d+)?)?)\s(?<z>-?\d+(.\d+(e-?\d+)?)?)/ end - end end