require './lib/toy_robot_simulator/command/matcher/base'
require './lib/toy_robot_simulator/pose'
require 'ostruct'

module Command
  module Matcher
    constantize_orientation = lambda do |string|
      case string
      when 'EAST'
        Pose::Orientation::EAST
      when 'NORTH'
        Pose::Orientation::NORTH
      when 'WEST'
        Pose::Orientation::WEST
      when 'SOUTH'
        Pose::Orientation::SOUTH
      end
    end

    place_args_extractor = lambda do |raw_command|
      x, y, f = raw_command.split.pop.split(',')

      OpenStruct.new(
        x: x.to_i,
        y: y.to_i,
        orientation: constantize_orientation.call(f)
      )
    end

    Place = Base.new(
      token: Command::Token::PLACE,
      regex: /\APLACE \d+,\d+,(NORTH|SOUTH|EAST|WEST)\z/,
      args_extractor: place_args_extractor
    )
  end
end

require './lib/toy_robot_simulator/command/matcher/base'
require './lib/toy_robot_simulator/pose'

module Command
  module Matcher
    constantize_orientation = lambda do |string|
      case string
      when 'EAST'
        Pose::Orientation::EAST
      when 'NORTH'
        Pose::Orientation::NORTH
      when 'WEST'
        Pose::Orientation::WEST
      when 'SOUTH'
        Pose::Orientation::SOUTH
      end
    end

    place_args_extractor = lambda do |raw_command|
      x, y, f = raw_command.split.pop.split(',')

      Pose.new(
        x: x.to_i,
        y: y.to_i,
        orientation: constantize_orientation.call(f)
      )
    end

    Place = Base.new(
      token: Command::Token::PLACE,
      regex: /\APLACE \d+,\d+,(NORTH|SOUTH|EAST|WEST)\z/,
      args_extractor: place_args_extractor
    )
  end
end

Fix bug in Command::Matcher::Place args_extractor()
Fix bug in Command::Matcher::Place args_extractor()

args_extractor() should return a Pose object but was returning an
OpenStruct instance. Ultimately this makes it dependant on Pose, a
better solution would be to re-design the Pose class to accept a
hash of attributes to mutate itself.
