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.
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
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
182 183 184 |
# File 'lib/milkode/grep/cli_grep.rb', line 182 def arguments @arguments end |
#gotowords ⇒ Object (readonly)
Returns the value of attribute gotowords.
184 185 186 |
# File 'lib/milkode/grep/cli_grep.rb', line 184 def gotowords @gotowords end |
#keywords ⇒ Object (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
#after ⇒ Object
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 |
#prev ⇒ Object
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 |