Module: EISCP::Parser::HumanReadableParser

Defined in:
lib/eiscp/parser/human_readable_parser.rb

Overview

This module parses a human readable command and returns a Message object

Class Method Summary collapse

Class Method Details

.parse(string) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/eiscp/parser/human_readable_parser.rb', line 10

def self.parse(string)
  array = string.split(' ')

  parsed_zone = if Dictionary.zones.include? array[0]
                  array.shift
                else
                  Dictionary::DEFAULT_ZONE
                end

  command_name = array.shift
  value_name = array.join(' ')
  command = Dictionary.command_name_to_command(command_name, parsed_zone)
  value = Dictionary.command_value_name_to_value(command, value_name)
  return nil if command.nil? || value.nil?

  Message.new(command: command, value: value)
end