optparse-simple 0.2.5 → 0.2.6

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 +15 -5
  2. metadata +2 -2
@@ -1,10 +1,12 @@
1
1
  require 'rexml/document'
2
+ require 'table-formatter'
2
3
  include REXML
3
4
 
4
5
  class OptParseSimple
5
6
 
6
7
  def initialize(s, args)
7
8
 
9
+ super()
8
10
  if s[/^https?:\/\//] then # url
9
11
  buffer = Kernel.open(s, 'UserAgent' => 'Polyrex-Reader').read
10
12
  elsif s[/\</] # xml
@@ -13,9 +15,9 @@ class OptParseSimple
13
15
  buffer = File.open(s,'r').read
14
16
  end
15
17
 
16
- doc = Document.new(buffer)
17
-
18
- @options = XPath.match(doc.root, 'records/option[summary/switch!=""]')
18
+ @doc = Document.new(buffer)
19
+
20
+ @options = XPath.match(@doc.root, 'records/option[summary/switch!=""]')
19
21
 
20
22
  switches = @options.map do |option|
21
23
  switch = option.text('summary/switch')
@@ -38,7 +40,7 @@ class OptParseSimple
38
40
 
39
41
  # -- bind any loose value to their argument
40
42
  xpath = 'records/option/summary[switch != "" and value != ""]'
41
- options = XPath.match(doc.root, xpath)\
43
+ options = XPath.match(@doc.root, xpath)\
42
44
  .map {|node| %w(switch alias)\
43
45
  .map{|x| node.text(x)}.compact}\
44
46
  .flatten
@@ -51,7 +53,7 @@ class OptParseSimple
51
53
  # -- end of bind any loose value to their argument
52
54
 
53
55
  a1 = options_match(@options[0], args).flatten.each_slice(2).map {|x| x if x[0]}.compact
54
- options_remaining = XPath.match(doc.root, 'records/option/summary[switch=""]/name/text()')
56
+ options_remaining = XPath.match(@doc.root, 'records/option/summary[switch=""]/name/text()')
55
57
  a2 = args.zip(options_remaining).map(&:reverse)
56
58
  if a2.map(&:first).all? then
57
59
  @h = Hash[*(a1+a2).map{|x,y| [x.to_s.to_sym, y]}.flatten]
@@ -64,6 +66,14 @@ class OptParseSimple
64
66
  def to_h()
65
67
  @h
66
68
  end
69
+
70
+ def help
71
+ a = XPath.match(@doc.root, 'records/option/summary').map do |summary|
72
+ %w(switch alias).map {|x| summary.text x}
73
+ end
74
+ puts 'options:'
75
+ puts TableFormatter.new(source: a, border: false).to_s
76
+ end
67
77
 
68
78
  private
69
79
 
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.5
4
+ version: 0.2.6
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-07-02 00:00:00 +01:00
12
+ date: 2010-07-04 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15