Class: Milkode::CLI_Grep::ArgumentParser
- Inherits:
-
Object
- Object
- Milkode::CLI_Grep::ArgumentParser
- Defined in:
- lib/milkode/grep/cli_grep.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#gotowords ⇒ Object
readonly
Returns the value of attribute gotowords.
-
#keywords ⇒ Object
readonly
Returns the value of attribute keywords.
Instance Method Summary collapse
- #after ⇒ Object
-
#initialize(arguments) ⇒ ArgumentParser
constructor
A new instance of ArgumentParser.
- #prev ⇒ Object
Constructor Details
#initialize(arguments) ⇒ ArgumentParser
Returns a new instance of ArgumentParser.
321 322 323 324 325 326 |
# File 'lib/milkode/grep/cli_grep.rb', line 321 def initialize(arguments) @arguments = arguments @state = :line @keywords = [] @gotowords = [] end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
317 318 319 |
# File 'lib/milkode/grep/cli_grep.rb', line 317 def arguments @arguments end |
#gotowords ⇒ Object (readonly)
Returns the value of attribute gotowords.
319 320 321 |
# File 'lib/milkode/grep/cli_grep.rb', line 319 def gotowords @gotowords end |
#keywords ⇒ Object (readonly)
Returns the value of attribute keywords.
318 319 320 |
# File 'lib/milkode/grep/cli_grep.rb', line 318 def keywords @keywords end |
Instance Method Details
#after ⇒ Object
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
# File 'lib/milkode/grep/cli_grep.rb', line 343 def after if @arguments.first if Util.gotoline_keyword? @arguments[0] @state = :gotoline end end result = [] @arguments.each do |v| case v when ":l" @state = :line next when ":k" @state = :keyword next when ":g" @state = :gotoline @gotowords += result result = [] next end case @state when :line result << v when :keyword @keywords << v when :gotoline @gotowords << v end end @arguments = result end |
#prev ⇒ Object
328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
# File 'lib/milkode/grep/cli_grep.rb', line 328 def prev @arguments.map! do |v| case v when "-l" ":l" when "-k" ":k" when "-g" ":g" else v end end end |