Sha256: ea35409d2bef684a70c111782933865387af23b123ae680eef1b0a217129ee08
Contents?: true
Size: 673 Bytes
Versions: 1
Compression:
Stored size: 673 Bytes
Contents
require "nasa_rovers/coord" module NasaRovers class Position class CardinalError < StandardError; end def self.factory(data) new(*data.split(" ")) end attr_reader :coord attr_accessor :cardinal def initialize(x, y, cardinal, coord_class=Coord) @coord = coord_class.new(x, y) @cardinal = check(cardinal) end def to_s "#{coord} #{cardinal}" end def ==(other) coord == other.coord && cardinal == other.cardinal end private def check(cardinal) return cardinal if CARDINALS.include?(cardinal) fail CardinalError.new("#{cardinal} is not a valid cardinal point") end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
nasa_rovers-1.0.1 | lib/nasa_rovers/position.rb |