key-value-parser 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d2e00095ab20a6984d6ad8a602c5e1c71181a509
4
- data.tar.gz: 0dd0fc09982b0d55bfdbabbda65b3eee147d702d
3
+ metadata.gz: 4ba87aebd5ceb2c84353cc7d02f24f868c464e52
4
+ data.tar.gz: ea0ae5d078b12ddd1b4eab24b7227bd44ee235bf
5
5
  SHA512:
6
- metadata.gz: 9457a9ebe4c75ce381ef2f0e007827e3cd6ea396f944a7aa5db0037fb7972b21e3c7b22f7c8ca9f0895ab9e52f89d49c210cd08ca69f94407fe27438355c58d4
7
- data.tar.gz: 78f7b302139bad8523391c15e603835ef44d6fff3dce1b4eab48080efcfcf2dcdbf156a80319bd1eca7e9dd1d427c6eeb00c67ac2fac2b8490258e7f96fcb063
6
+ metadata.gz: 8581f6e7b13564742b4c493a4681e186fe4edcfd6d472ffb4740fa220e279169c738e99a496c15cb3cfa2f8e3814203e93e57f877b9668a5a05aa874ded9c99e
7
+ data.tar.gz: 134f4c28ff4db74f530775b2f9e7d42db36dc8675dabd96472fe0d09e88a9e18bcab33dbc1951f04c6186b144b01dedfe3cdfd0ea10e23ee444e0238c6976727
data/README.md CHANGED
@@ -3,7 +3,7 @@ Key Value Parser
3
3
 
4
4
  The primary purpose of `KeyValueParser` is to have a
5
5
  simple class to be able to parse command line arguments
6
- which are all formated as `key:value`.
6
+ which are all formated as `key=value`.
7
7
 
8
8
  For example you could call a script like this:
9
9
 
@@ -53,7 +53,7 @@ Typecasted Values
53
53
  -----------------
54
54
 
55
55
  As you may have noticed in previous examples, values are
56
- typecasted. So far it does typecast integers and booleans.
56
+ typecasted. So far it does typecast integers, floats and booleans.
57
57
  Also if you don't give a value, the parser will interpret
58
58
  it as a flag and set it to `true`.
59
59
 
@@ -65,12 +65,12 @@ options[:broadcast] == false
65
65
  options[:running] == true
66
66
  ```
67
67
 
68
- If you don't want to cast values, you can use the second of
68
+ If you don't want to cast values, you can use the second argument of
69
69
  `KeyValueParse#parse` which is a list of options. Just set
70
70
  `typecast_values` to `false`.
71
71
 
72
72
  ```ruby
73
- parser = KeyValueparser.new({}, {typecast_values: false})
73
+ parser = KeyValueParser.new({}, {typecast_values: false})
74
74
  ```
75
75
 
76
76
  Typecasting is still very basic and will most likely evolve,
@@ -81,7 +81,7 @@ Normalized Keys
81
81
 
82
82
  Keys of the resulting `Hash` are normalized. Dash in the middle
83
83
  of words are replaced by underscores. Double dash in front of a
84
- word are also removed. It allows you to have unix style dash
84
+ word are also removed. It allows you to have unix style double dash
85
85
  arguments.
86
86
 
87
87
  ```ruby
@@ -92,7 +92,7 @@ options[:user_name] == 'bob'
92
92
 
93
93
  Because of the way command line arguments are created for `ARGV`
94
94
  you can even surround an argument with quotes in order to have
95
- spaces in the arguments value.
95
+ spaces in the argument's value.
96
96
 
97
97
  There is nothing yet for unix style single dash arguments.
98
98
  I could remove the dash and treat it like a single letter key,
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
6
6
  s.licenses = ['MIT']
7
7
 
8
8
  s.name = 'key-value-parser'
9
- s.version = '0.0.1'
9
+ s.version = '0.0.2'
10
10
  s.summary = "Key Value Parser"
11
11
  s.description = "KeyValueParser parses arrays of string options like 'machine=coconut'. It is mainly done for parsing ARGV, but can be used for other things."
12
12
 
@@ -43,7 +43,9 @@ class KeyValueParser
43
43
  v = true
44
44
  elsif v=='false'
45
45
  v = false
46
- elsif v=~/^\d+$/
46
+ elsif v=~/^-?\d*\.\d+$/
47
+ v = v.to_f
48
+ elsif v=~/^-?\d+$/
47
49
  v = v.to_i
48
50
  else
49
51
  v
@@ -32,8 +32,20 @@ class TestKeyValueParser < Minitest::Test
32
32
  end
33
33
 
34
34
  def test_integers_are_typecasted
35
- kvs = ['machine:coconut', 'size:11']
36
- expected = {machine: 'coconut', size: 11}
35
+ kvs = ['machine:1coconut', 'size:11', 'negative:-5']
36
+ expected = {machine: '1coconut', size: 11, negative: -5}
37
+ assert_equal expected, @parser.parse(kvs)
38
+ end
39
+
40
+ def test_floats_are_typecasted
41
+ kvs = [
42
+ 'machine:5.0coconut',
43
+ 'float1:99.99', 'float2:-5.0', 'float3:.4'
44
+ ]
45
+ expected = {
46
+ machine: '5.0coconut',
47
+ float1: 99.99, float2: -5.0, float3: 0.4
48
+ }
37
49
  assert_equal expected, @parser.parse(kvs)
38
50
  end
39
51
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: key-value-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mickael Riga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-24 00:00:00.000000000 Z
11
+ date: 2016-10-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: KeyValueParser parses arrays of string options like 'machine=coconut'.
14
14
  It is mainly done for parsing ARGV, but can be used for other things.
@@ -45,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
45
  version: '0'
46
46
  requirements: []
47
47
  rubyforge_project:
48
- rubygems_version: 2.4.5.1
48
+ rubygems_version: 2.5.1
49
49
  signing_key:
50
50
  specification_version: 4
51
51
  summary: Key Value Parser