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.



308
309
310
311
312
313
# File 'lib/milkode/grep/cli_grep.rb', line 308

def initialize(arguments)
  @arguments = arguments
  @state = :line
  @keywords = []
  @gotowords = []
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



304
305
306
# File 'lib/milkode/grep/cli_grep.rb', line 304

def arguments
  @arguments
end

#gotowordsObject (readonly)

Returns the value of attribute gotowords.



306
307
308
# File 'lib/milkode/grep/cli_grep.rb', line 306

def gotowords
  @gotowords
end

#keywordsObject (readonly)

Returns the value of attribute keywords.



305
306
307
# File 'lib/milkode/grep/cli_grep.rb', line 305

def keywords
  @keywords
end

Instance Method Details

#afterObject



330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/milkode/grep/cli_grep.rb', line 330

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



315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/milkode/grep/cli_grep.rb', line 315

def prev
  @arguments.map! do |v|
    case v
    when "-l"
      ":l"
    when "-k"
      ":k"
    when "-g"
      ":g"
    else
      v
    end
  end
end