Class: Milkode::CLI_Grep::ArgumentParser

Inherits:
Object
  • Object
show all
Defined in:
lib/milkode/grep/cli_grep.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#argumentsObject (readonly)

Returns the value of attribute arguments.



317
318
319
# File 'lib/milkode/grep/cli_grep.rb', line 317

def arguments
  @arguments
end

#gotowordsObject (readonly)

Returns the value of attribute gotowords.



319
320
321
# File 'lib/milkode/grep/cli_grep.rb', line 319

def gotowords
  @gotowords
end

#keywordsObject (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

#afterObject



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

#prevObject



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