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.



186
187
188
189
190
191
# File 'lib/milkode/grep/cli_grep.rb', line 186

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

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



182
183
184
# File 'lib/milkode/grep/cli_grep.rb', line 182

def arguments
  @arguments
end

#gotowordsObject (readonly)

Returns the value of attribute gotowords.



184
185
186
# File 'lib/milkode/grep/cli_grep.rb', line 184

def gotowords
  @gotowords
end

#keywordsObject (readonly)

Returns the value of attribute keywords.



183
184
185
# File 'lib/milkode/grep/cli_grep.rb', line 183

def keywords
  @keywords
end

Instance Method Details

#afterObject



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/milkode/grep/cli_grep.rb', line 201

def after
  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



193
194
195
196
197
198
199
# File 'lib/milkode/grep/cli_grep.rb', line 193

def prev
  @arguments.map! do |v|
    v.gsub("-l", ":l").
      gsub("-k", ":k").
      gsub("-g", ":g")            
  end
end