Class: Lucie::Core::CommandLineSlicer

Inherits:
Object
  • Object
show all
Defined in:
lib/lucie/command_line_slicer.rb

Overview

Command Line Slicer can split the input string to words.

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ CommandLineSlicer

Initializes a CommandLineSlicer object with the input.

Parameters:

  • line (String)

    The input that need to be sliced



11
12
13
14
15
16
17
# File 'lib/lucie/command_line_slicer.rb', line 11

def initialize(line)
  @line = line.split("")
  @parts = []
  @neutral_status = false
  @quotation_open = false
  @scanned = ""
end

Instance Method Details

#to_aObject

Returns the words of the input in an array.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/lucie/command_line_slicer.rb', line 21

def to_a
  each_char do |char|
    if boundary? char
      save_chunk
    elsif in_quoatation? char
      toggle_quotation_state
    elsif neutral? char
      neutral :on
    else
      neutral :off
      append char
    end
  end
  save_chunk
end