Class: Mysh::InputWrapper
Overview
An action compatible wrapper for a input.
Instance Attribute Summary collapse
-
#raw ⇒ Object
readonly
Access the raw text.
Instance Method Summary collapse
-
#args ⇒ Object
Get the parsed arguments.
-
#cooked ⇒ Object
Access the massaged text.
-
#cooked_body ⇒ Object
Get the preprocessed argument text.
-
#initialize(raw) ⇒ InputWrapper
constructor
Build an input wrapper.
-
#parsed ⇒ Object
Get the parsed command line.
-
#quick ⇒ Object
Set up input for a quick style command.
-
#quick_body ⇒ Object
Get the balance of the raw string.
-
#quick_command ⇒ Object
Get the first raw character.
-
#raw_body ⇒ Object
Get the parameter text.
-
#raw_command ⇒ Object
Get the command word if it exists.
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
#raw ⇒ Object (readonly)
Access the raw text.
16 17 18 |
# File 'lib/mysh/input_wrapper.rb', line 16 def raw @raw end |
Instance Method Details
#args ⇒ Object
Get the parsed arguments
50 51 52 |
# File 'lib/mysh/input_wrapper.rb', line 50 def args Mysh.parse_args(cooked_body) end |
#cooked ⇒ Object
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_body ⇒ Object
Get the preprocessed argument text.
39 40 41 |
# File 'lib/mysh/input_wrapper.rb', line 39 def cooked_body raw_body.preprocess end |
#parsed ⇒ Object
Get the parsed command line.
55 56 57 |
# File 'lib/mysh/input_wrapper.rb', line 55 def parsed [raw_command] + args end |
#quick ⇒ Object
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_body ⇒ Object
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_command ⇒ Object
Get the first raw character.
19 20 21 |
# File 'lib/mysh/input_wrapper.rb', line 19 def quick_command @raw[0] || "" end |
#raw_body ⇒ Object
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_command ⇒ Object
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 |