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.
2160 2161 2162 2163 |
# File 'lib/como.rb', line 2160 def initialize( list ) set( list ) @idx = 0 end |
Instance Method Details
#done? ⇒ Boolean
Parser at argument list end?
2196 2197 2198 |
# File 'lib/como.rb', line 2196 def done? @idx >= @list.length end |
#get(idx = @idx) ⇒ Object
Get current argument.
2181 2182 2183 |
# File 'lib/como.rb', line 2181 def get( idx = @idx ) @args[ idx ] end |
#isOpt(str = get) ⇒ Object
Test whether str is an option.
2201 2202 2203 |
# File 'lib/como.rb', line 2201 def isOpt( str = get ) str[0..0] == "-" end |
#isOptTerm(str = get) ⇒ Object
Test whether str is an option list terminator.
2206 2207 2208 |
# File 'lib/como.rb', line 2206 def isOptTerm( str = get ) str == "--" end |
#last(idx = @idx) ⇒ Object
Get last argument.
2186 2187 2188 |
# File 'lib/como.rb', line 2186 def last( idx = @idx ) idx == ( @args.length-1 ) end |
#next ⇒ Object
Step to next argument.
2171 2172 2173 |
# File 'lib/como.rb', line 2171 def next @idx += 1 end |
#prev ⇒ Object
Step to previous argument.
2176 2177 2178 |
# File 'lib/como.rb', line 2176 def prev @idx -= 1 end |
#rest(idx = @idx) ⇒ Object
Get rest of the arguments.
2191 2192 2193 |
# File 'lib/como.rb', line 2191 def rest( idx = @idx ) @args[ idx..-1 ] end |
#set(list) ⇒ Object
Set list of arguments.
2166 2167 2168 |
# File 'lib/como.rb', line 2166 def set( list ) @args = list end |
#toValue(str = get) ⇒ Object
Format value string if escaped.
2211 2212 2213 2214 2215 2216 2217 |
# File 'lib/como.rb', line 2211 def toValue( str = get ) if str[0..0] == "\\" str[1..-1] else str end end |