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.
323 324 325 326 327 328 |
# File 'lib/milkode/grep/cli_grep.rb', line 323 def initialize(arguments) @arguments = arguments @state = :line @keywords = [] @gotowords = [] end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
319 320 321 |
# File 'lib/milkode/grep/cli_grep.rb', line 319 def arguments @arguments end |
#gotowords ⇒ Object (readonly)
Returns the value of attribute gotowords.
321 322 323 |
# File 'lib/milkode/grep/cli_grep.rb', line 321 def gotowords @gotowords end |
#keywords ⇒ Object (readonly)
Returns the value of attribute keywords.
320 321 322 |
# File 'lib/milkode/grep/cli_grep.rb', line 320 def keywords @keywords end |
Instance Method Details
#after ⇒ Object
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 379 380 |
# File 'lib/milkode/grep/cli_grep.rb', line 345 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
330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/milkode/grep/cli_grep.rb', line 330 def prev @arguments.map! do |v| case v when "-l" ":l" when "-k" ":k" when "-g" ":g" else v end end end |