lucy-goosey 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +1 -1
- data/lib/lucy-goosey.rb +9 -0
- data/lib/lucy-goosey/version.rb +1 -1
- data/test/options_parsing_test.rb +5 -0
- metadata +3 -3
data/README.md
CHANGED
data/lib/lucy-goosey.rb
CHANGED
@@ -4,11 +4,20 @@ module Lucy
|
|
4
4
|
module Goosey
|
5
5
|
UNIX_SINGLE_FLAG = /^-/
|
6
6
|
UNIX_DOUBLE_FLAG = /^--/
|
7
|
+
EQUAL = /=/
|
8
|
+
|
9
|
+
|
10
|
+
def self.leading_word?(word)
|
11
|
+
! (word.match(UNIX_DOUBLE_FLAG) || word.match(UNIX_SINGLE_FLAG) || word.match(EQUAL))
|
12
|
+
end
|
13
|
+
|
7
14
|
|
8
15
|
def self.parse_options(_args)
|
9
16
|
args = _args.dup
|
10
17
|
config = {}
|
11
18
|
|
19
|
+
args = args[1..-1] while leading_word?(args.first)
|
20
|
+
|
12
21
|
args.size.times do
|
13
22
|
break if args.empty?
|
14
23
|
arg = args.shift
|
data/lib/lucy-goosey/version.rb
CHANGED
@@ -100,6 +100,11 @@ describe Lucy::Goosey do
|
|
100
100
|
end
|
101
101
|
|
102
102
|
describe "edge cases" do
|
103
|
+
it "ignores leading words" do
|
104
|
+
result = Lucy::Goosey.parse_options(%w(wtf bbq --bar foo=baz --baz=bar -n 1 --bap))
|
105
|
+
result.must_equal({ 'foo' => 'baz', 'baz' => 'bar', 'bar' => true, 'n' => '1', 'bap' => true })
|
106
|
+
end
|
107
|
+
|
103
108
|
it "works in any order" do
|
104
109
|
result = Lucy::Goosey.parse_options(%w(--bar foo=baz --baz=bar bob=true --bap))
|
105
110
|
result.must_equal({ 'foo' => 'baz', 'baz' => 'bar', 'bar' => true, 'bob' => true, 'bap' => true })
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lucy-goosey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -74,7 +74,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
74
74
|
version: '0'
|
75
75
|
segments:
|
76
76
|
- 0
|
77
|
-
hash:
|
77
|
+
hash: -3205257808649039205
|
78
78
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
79
|
none: false
|
80
80
|
requirements:
|
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
83
|
version: '0'
|
84
84
|
segments:
|
85
85
|
- 0
|
86
|
-
hash:
|
86
|
+
hash: -3205257808649039205
|
87
87
|
requirements: []
|
88
88
|
rubyforge_project:
|
89
89
|
rubygems_version: 1.8.23
|