optopus 0.2.2 → 0.2.3

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.
Files changed (2) hide show
  1. data/lib/optopus.rb +28 -19
  2. metadata +7 -5
@@ -186,34 +186,43 @@ module Optopus
186
186
 
187
187
  next unless value
188
188
 
189
- value = orig_val = value.to_s
189
+ check_block = lambda do |unit|
190
+ unit = orig_val = unit.to_s
190
191
 
191
- if type = args.find {|i| i.kind_of?(Class) }
192
- pat, conv = OptionParser::DefaultList.atype[type]
192
+ if type = args.find {|i| i.kind_of?(Class) }
193
+ pat, conv = OptionParser::DefaultList.atype[type]
193
194
 
194
- if pat and pat !~ value
195
- raise OptionParser::InvalidArgument.new(v, "(#{key}: #{value})")
195
+ if pat and pat !~ unit
196
+ raise OptionParser::InvalidArgument.new(v, "(#{key}: #{unit})")
197
+ end
198
+
199
+ unit = conv.call(unit) if conv
200
+ elsif type = args.find {|i| i.kind_of?(Array) }
201
+ unless type.map {|i| i.to_s }.include?(unit.to_s)
202
+ raise OptionParser::InvalidArgument.new(key, unit)
203
+ end
204
+
205
+ unit = unit.to_s.to_sym
196
206
  end
197
207
 
198
- value = conv.call(value) if conv
199
- elsif type = args.find {|i| i.kind_of?(Array) }
200
- unless type.map {|i| i.to_s }.include?(value.to_s)
201
- raise OptionParser::InvalidArgument.new(key, value)
208
+ if unit and block
209
+ begin
210
+ CheckerContext.evaluate(v, unit, &block)
211
+ rescue OptionParser::ParseError => e
212
+ errmsg = "#{e.message}: #{key}=#{orig_val}"
213
+ raise OptionParser::ParseError, errmsg
214
+ end
202
215
  end
203
216
 
204
- value = value.to_s.to_sym
217
+ return unit
205
218
  end
206
219
 
207
- if value and block
208
- begin
209
- CheckerContext.evaluate(v, value, &block)
210
- rescue OptionParser::ParseError => e
211
- errmsg = "#{e.message}: #{key}=#{orig_val}"
212
- raise OptionParser::ParseError, errmsg
213
- end
220
+ if multiple
221
+ value = [value] unless value.kind_of?(Array)
222
+ options[name] = value.map {|i| check_block.call(i) }
223
+ else
224
+ options[name] = check_block.call(value)
214
225
  end
215
-
216
- options[name] = value
217
226
  end
218
227
  end # file_args_checker
219
228
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optopus
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 3
10
+ version: 0.2.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - winebarrel
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-12-26 00:00:00 Z
18
+ date: 2012-01-06 00:00:00 +09:00
19
+ default_executable:
19
20
  dependencies: []
20
21
 
21
22
  description:
@@ -29,6 +30,7 @@ extra_rdoc_files: []
29
30
  files:
30
31
  - README
31
32
  - lib/optopus.rb
33
+ has_rdoc: true
32
34
  homepage: https://bitbucket.org/winebarrel/optopus
33
35
  licenses: []
34
36
 
@@ -58,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
60
  requirements: []
59
61
 
60
62
  rubyforge_project:
61
- rubygems_version: 1.8.11
63
+ rubygems_version: 1.4.2
62
64
  signing_key:
63
65
  specification_version: 3
64
66
  summary: optopus is an easy-to-use option purser.