optparse-simple 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/optparse-simple.rb +22 -13
  2. metadata +2 -2
@@ -4,22 +4,17 @@ include REXML
4
4
  class OptParseSimple
5
5
 
6
6
  def initialize(filename, args)
7
- doc = Document.new(File.open(filename,'r').read)
8
7
 
9
- # -- bind any loose value to their argument
10
- xpath = 'records/option/summary[switch != "" and value != ""]'
11
- options = XPath.match(doc.root, xpath)\
12
- .map {|node| %w(switch alias)\
13
- .map{|x| node.text(x)}.compact}\
14
- .flatten
15
- args.map!.with_index do |x,i|
16
- next unless x or i < args.length - 1
17
- (x += '=' + args[i+1]; args[i+1] = nil) if options.include?(x)
18
- x
8
+ if s[/^https?:\/\//] then # url
9
+ buffer = Kernel.open(s, 'UserAgent' => 'Polyrex-Reader').read
10
+ elsif s[/\</] # xml
11
+ buffer = s
12
+ else # local file
13
+ buffer = File.open(s,'r').read
19
14
  end
20
- args.compact!
21
- # -- end of bind any loose value to their argument
22
15
 
16
+ doc = Document.new(buffer)
17
+
23
18
  @options = XPath.match(doc.root, 'records/option[summary/switch!=""]')
24
19
 
25
20
  switches = @options.map do |option|
@@ -41,6 +36,20 @@ class OptParseSimple
41
36
 
42
37
  args.flatten!
43
38
 
39
+ # -- bind any loose value to their argument
40
+ xpath = 'records/option/summary[switch != "" and value != ""]'
41
+ options = XPath.match(doc.root, xpath)\
42
+ .map {|node| %w(switch alias)\
43
+ .map{|x| node.text(x)}.compact}\
44
+ .flatten
45
+ args.map!.with_index do |x,i|
46
+ next unless x or i < args.length - 1
47
+ (x += '=' + args[i+1]; args[i+1] = nil) if options.include?(x)
48
+ x
49
+ end
50
+ args.compact!
51
+ # -- end of bind any loose value to their argument
52
+
44
53
  a1 = options_match(@options[0], args).flatten.each_slice(2).map {|x| x if x[0]}.compact
45
54
  options_remaining = XPath.match(doc.root, 'records/option/summary[switch=""]/name/text()')
46
55
  a2 = args.zip(options_remaining).map(&:reverse)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optparse-simple
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors: []
7
7
 
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-05-12 00:00:00 +01:00
12
+ date: 2010-07-02 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15