Class: Mysh::InputWrapper

Inherits:
Object show all
Defined in:
lib/mysh/input_wrapper.rb

Overview

An action compatible wrapper for a input.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ InputWrapper

Build an input wrapper.



10
11
12
13
# File 'lib/mysh/input_wrapper.rb', line 10

def initialize(raw)
  @raw = raw.chomp
  @raw_command = @raw_body = nil
end

Instance Attribute Details

#rawObject (readonly)

Access the raw text.



16
17
18
# File 'lib/mysh/input_wrapper.rb', line 16

def raw
  @raw
end

Instance Method Details

#argsObject

Get the parsed arguments



50
51
52
# File 'lib/mysh/input_wrapper.rb', line 50

def args
  Mysh.parse_args(cooked_body)
end

#cookedObject

Access the massaged text.



44
45
46
47
# File 'lib/mysh/input_wrapper.rb', line 44

def cooked
  body = cooked_body
  raw_command + (body.empty? ? "" : " " + body)
end

#cooked_bodyObject

Get the preprocessed argument text.



39
40
41
# File 'lib/mysh/input_wrapper.rb', line 39

def cooked_body
  raw_body.preprocess
end

#parsedObject

Get the parsed command line.



55
56
57
# File 'lib/mysh/input_wrapper.rb', line 55

def parsed
  [raw_command] + args
end

#quickObject

Set up input for a quick style command.



60
61
62
63
64
# File 'lib/mysh/input_wrapper.rb', line 60

def quick
  @raw_command = quick_command
  @raw_body    = quick_body
  self
end

#quick_bodyObject

Get the balance of the raw string.



24
25
26
# File 'lib/mysh/input_wrapper.rb', line 24

def quick_body
  @raw[1..-1] || ""
end

#quick_commandObject

Get the first raw character.



19
20
21
# File 'lib/mysh/input_wrapper.rb', line 19

def quick_command
  @raw[0] || ""
end

#raw_bodyObject

Get the parameter text.



34
35
36
# File 'lib/mysh/input_wrapper.rb', line 34

def raw_body
  @raw_body ||= @raw[(raw_command.length + 1)..-1] || ""
end

#raw_commandObject

Get the command word if it exists.



29
30
31
# File 'lib/mysh/input_wrapper.rb', line 29

def raw_command
  @raw_command ||= @raw.split[0] || ""
end