Class: Como::ArgsParseState
- Inherits:
-
Object
- Object
- Como::ArgsParseState
- Defined in:
- lib/como.rb
Overview
Command argument parsing state.
Instance Method Summary collapse
-
#done? ⇒ Boolean
Parser at argument list end?.
-
#get(idx = @idx) ⇒ Object
Get current argument.
-
#initialize(list) ⇒ ArgsParseState
constructor
Create parse state.
-
#isOpt(str = get) ⇒ Object
Test whether str is an option.
-
#isOptTerm(str = get) ⇒ Object
Test whether str is an option list terminator.
-
#last(idx = @idx) ⇒ Object
Get last argument.
-
#next ⇒ Object
Step to next argument.
-
#prev ⇒ Object
Step to previous argument.
-
#rest(idx = @idx) ⇒ Object
Get rest of the arguments.
-
#set(list) ⇒ Object
Set list of arguments.
-
#toValue(str = get) ⇒ Object
Format value string if escaped.
Constructor Details
#initialize(list) ⇒ ArgsParseState
Create parse state.
2121 2122 2123 2124 |
# File 'lib/como.rb', line 2121 def initialize( list ) set( list ) @idx = 0 end |
Instance Method Details
#done? ⇒ Boolean
Parser at argument list end?
2157 2158 2159 |
# File 'lib/como.rb', line 2157 def done? @idx >= @list.length end |
#get(idx = @idx) ⇒ Object
Get current argument.
2142 2143 2144 |
# File 'lib/como.rb', line 2142 def get( idx = @idx ) @args[ idx ] end |
#isOpt(str = get) ⇒ Object
Test whether str is an option.
2163 2164 2165 |
# File 'lib/como.rb', line 2163 def isOpt( str = get ) str[0..0] == "-" end |
#isOptTerm(str = get) ⇒ Object
Test whether str is an option list terminator.
2168 2169 2170 |
# File 'lib/como.rb', line 2168 def isOptTerm( str = get ) str == "--" end |
#last(idx = @idx) ⇒ Object
Get last argument.
2147 2148 2149 |
# File 'lib/como.rb', line 2147 def last( idx = @idx ) idx == ( @args.length-1 ) end |
#next ⇒ Object
Step to next argument.
2132 2133 2134 |
# File 'lib/como.rb', line 2132 def next @idx += 1 end |
#prev ⇒ Object
Step to previous argument.
2137 2138 2139 |
# File 'lib/como.rb', line 2137 def prev @idx -= 1 end |
#rest(idx = @idx) ⇒ Object
Get rest of the arguments.
2152 2153 2154 |
# File 'lib/como.rb', line 2152 def rest( idx = @idx ) @args[ idx..-1 ] end |
#set(list) ⇒ Object
Set list of arguments.
2127 2128 2129 |
# File 'lib/como.rb', line 2127 def set( list ) @args = list end |
#toValue(str = get) ⇒ Object
Format value string if escaped.
2173 2174 2175 2176 2177 2178 2179 |
# File 'lib/como.rb', line 2173 def toValue( str = get ) if str[0..0] == "\\" str[1..-1] else str end end |