summaryrefslogtreecommitdiff
path: root/lib/slop/parser.rb
diff options
context:
space:
mode:
authorLee Jarvis <ljjarvis@gmail.com>2014-11-19 09:12:38 +0000
committerLee Jarvis <ljjarvis@gmail.com>2014-11-19 09:12:47 +0000
commit253dcd9622328d5f7a5a695c3bf487b65565fb9e (patch)
tree846b4a6579b3b871558fb271302c114822e46ac9 /lib/slop/parser.rb
parentb91db74b327848841bee30cbecead14c45e3a260 (diff)
downloadslop-253dcd9622328d5f7a5a695c3bf487b65565fb9e.tar.gz
Basic option parsing
Diffstat (limited to 'lib/slop/parser.rb')
-rw-r--r--lib/slop/parser.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/slop/parser.rb b/lib/slop/parser.rb
index 0ede9d8..3bcb0a9 100644
--- a/lib/slop/parser.rb
+++ b/lib/slop/parser.rb
@@ -1,5 +1,30 @@
module Slop
class Parser
+ attr_reader :options
+ def initialize(options)
+ @options = options
+ end
+
+ def parse(strings)
+ pairs = strings.each_cons(2).to_a
+ pairs << [strings.last, nil]
+
+ pairs.each do |flag, arg|
+ option = matching_option(flag)
+
+ if option
+ option.call(arg)
+ end
+ end
+
+ Result.new(self)
+ end
+
+ private
+
+ def matching_option(flag)
+ options.find { |o| o.flags.include?(flag) }
+ end
end
end