args_parser 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.0.3 2012-09-24
2
+
3
+ * cast Integer and Float
4
+
1
5
  === 0.0.2 2012-06-11
2
6
 
3
7
  * fix syntax warn on ruby1.9.2
data/README.rdoc CHANGED
@@ -39,11 +39,17 @@ parse ARGV
39
39
 
40
40
  * Ruby 1.8.7+
41
41
  * Ruby 1.9.3+
42
+ * JRuby 1.6.7+
42
43
 
43
44
  == INSTALL:
44
45
 
45
46
  * gem install args_parser
46
47
 
48
+ == TEST:
49
+
50
+ % bundle install
51
+ % rake
52
+
47
53
  == LICENSE:
48
54
 
49
55
  (The MIT License)
@@ -62,6 +62,8 @@ module ArgsParser
62
62
  k = arg.scan(/^-+([^-\s]+)$/)[0][0].strip.to_sym
63
63
  k = aliases[k] if aliases[k]
64
64
  else
65
+ arg = arg.to_i if arg =~ /^\d+$/
66
+ arg = arg.to_f if arg =~ /^\d+\.\d+$/
65
67
  params[k][:value] = arg
66
68
  k = nil
67
69
  end
@@ -89,7 +91,7 @@ module ArgsParser
89
91
  def has_param?(*param_)
90
92
  !(param_.flatten.map{|i|
91
93
  v = self[i]
92
- (v and v.kind_of? String) ? true : false
94
+ (v and [String, Fixnum, Float].include? v.class) ? true : false
93
95
  }.include? false)
94
96
  end
95
97
 
data/lib/args_parser.rb CHANGED
@@ -4,5 +4,5 @@ $:.unshift(File.dirname(__FILE__)) unless
4
4
  require 'args_parser/parser'
5
5
 
6
6
  module ArgsParser
7
- VERSION = '0.0.2'
7
+ VERSION = '0.0.3'
8
8
  end
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/test_helper.rb'
2
2
 
3
3
  class TestArgsParser < Test::Unit::TestCase
4
4
  def setup
5
- @argv = 'test --input ~/tmp -a --o ./out -h'.split(/\s+/)
5
+ @argv = 'test --input ~/tmp -a --o ./out -h --depth 030 --pi 3.14'.split(/\s+/)
6
6
  @parser = ArgsParser.parse @argv do
7
7
  arg :input, 'input dir', :alias => :i
8
8
  arg :output, 'output dir', :alias => :o
@@ -22,8 +22,18 @@ class TestArgsParser < Test::Unit::TestCase
22
22
  assert @parser[:output] == './out'
23
23
  end
24
24
 
25
+ def test_cast_integer
26
+ assert @parser[:depth] == 30
27
+ assert @parser[:depth].class == Fixnum
28
+ end
29
+
30
+ def test_cast_float
31
+ assert @parser[:pi] == 3.14
32
+ assert @parser[:pi].class == Float
33
+ end
34
+
25
35
  def test_missing_arg
26
- assert @parser[:a] == true
36
+ assert @parser[:b] != true
27
37
  end
28
38
 
29
39
  def test_switch
@@ -33,10 +43,12 @@ class TestArgsParser < Test::Unit::TestCase
33
43
  def test_has_param?
34
44
  assert @parser.has_param? :input
35
45
  assert @parser.has_param? :output
46
+ assert @parser.has_param? :depth
47
+ assert @parser.has_param? :pi
36
48
  end
37
49
 
38
50
  def test_has_params?
39
- assert @parser.has_param? :input, :output
51
+ assert @parser.has_param? :input, :output, :depth, :pi
40
52
  end
41
53
 
42
54
  def test_has_not_param?
data/test/test_helper.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'bundler/setup'
1
2
  require 'stringio'
2
3
  require 'test/unit'
3
4
  require File.dirname(__FILE__) + '/../lib/args_parser'
metadata CHANGED
@@ -1,74 +1,80 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: args_parser
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Sho Hashimoto
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-06-11 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: rdoc
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: '3.10'
22
- type: :development
17
+
18
+ date: 2012-09-24 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
23
21
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
22
+ requirement: &id001 !ruby/object:Gem::Requirement
25
23
  none: false
26
- requirements:
24
+ requirements:
27
25
  - - ~>
28
- - !ruby/object:Gem::Version
29
- version: '3.10'
30
- - !ruby/object:Gem::Dependency
31
- name: newgem
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: 1.5.3
26
+ - !ruby/object:Gem::Version
27
+ hash: 19
28
+ segments:
29
+ - 3
30
+ - 10
31
+ version: "3.10"
38
32
  type: :development
33
+ name: rdoc
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
39
36
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
37
+ requirement: &id002 !ruby/object:Gem::Requirement
41
38
  none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 5
43
+ segments:
44
+ - 1
45
+ - 5
46
+ - 3
45
47
  version: 1.5.3
46
- - !ruby/object:Gem::Dependency
47
- name: hoe
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ~>
52
- - !ruby/object:Gem::Version
53
- version: '3.0'
54
48
  type: :development
49
+ name: newgem
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
55
52
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
53
+ requirement: &id003 !ruby/object:Gem::Requirement
57
54
  none: false
58
- requirements:
55
+ requirements:
59
56
  - - ~>
60
- - !ruby/object:Gem::Version
61
- version: '3.0'
57
+ - !ruby/object:Gem::Version
58
+ hash: 5
59
+ segments:
60
+ - 3
61
+ - 1
62
+ version: "3.1"
63
+ type: :development
64
+ name: hoe
65
+ version_requirements: *id003
62
66
  description: ARGV parser - Parse args from command line.
63
- email:
67
+ email:
64
68
  - hashimoto@shokai.org
65
69
  executables: []
70
+
66
71
  extensions: []
67
- extra_rdoc_files:
72
+
73
+ extra_rdoc_files:
68
74
  - History.txt
69
75
  - Manifest.txt
70
76
  - README.rdoc
71
- files:
77
+ files:
72
78
  - History.txt
73
79
  - Manifest.txt
74
80
  - README.rdoc
@@ -84,30 +90,38 @@ files:
84
90
  - .gemtest
85
91
  homepage: http://github.com/shokai/args_parser
86
92
  licenses: []
93
+
87
94
  post_install_message:
88
- rdoc_options:
95
+ rdoc_options:
89
96
  - --main
90
97
  - README.rdoc
91
- require_paths:
98
+ require_paths:
92
99
  - lib
93
- required_ruby_version: !ruby/object:Gem::Requirement
100
+ required_ruby_version: !ruby/object:Gem::Requirement
94
101
  none: false
95
- requirements:
96
- - - ! '>='
97
- - !ruby/object:Gem::Version
98
- version: '0'
99
- required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
110
  none: false
101
- requirements:
102
- - - ! '>='
103
- - !ruby/object:Gem::Version
104
- version: '0'
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
105
118
  requirements: []
119
+
106
120
  rubyforge_project: args_parser
107
121
  rubygems_version: 1.8.24
108
122
  signing_key:
109
123
  specification_version: 3
110
124
  summary: ARGV parser - Parse args from command line.
111
- test_files:
125
+ test_files:
112
126
  - test/test_args_parser.rb
113
127
  - test/test_helper.rb