kvn 0.2.0 → 0.2.1

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: 832c9ff0fe7496bfe3c6f5a93cc7b959e8889cb2
4
- data.tar.gz: 05dd1ba7428b883dc2fe7669ae70fa180f14c383
3
+ metadata.gz: f60f237fab1696948ebeffb4f1a54b9a97cd1504
4
+ data.tar.gz: b9a098956d24fd5264e4d3511420f4fbd8a434b1
5
5
  SHA512:
6
- metadata.gz: 2ec2564e05c43f19bd5897d58cf7bda7392817ce7bcb738e44abec846deccc332893d292565b9855605385462383d7309164ee52729f3060ccd7808cdfbbf28c
7
- data.tar.gz: 2f00b76e616acf6177ca67558004c89545fb9adb0a616fac958f3eabc9c28db556ac626cb36bc563bc02f12fb0d37dffa6ec2d5d7f09c4fcdd7e3b176fd9a761
6
+ metadata.gz: 579bbe99256d64811ccf7101c3323e1fa48d1be0586084913e5a5cce7338b95dc146c375284418f8f9132512e9ba788e0e00a5da4fd6023d073f4ca9872c1f05
7
+ data.tar.gz: 51fd08a474ea5e563d669364ccaffec6c3ed84efd62395e666ca485d88c36a36c3b891c8ab53a8c02492059a7a6166e7f129ebc13b432628fcc6d1b37b1a3d49
@@ -11,18 +11,25 @@ GEM
11
11
  debug_inspector (>= 0.0.1)
12
12
  byebug (8.2.2)
13
13
  coderay (1.1.1)
14
- coveralls (0.8.13)
14
+ coveralls (0.8.10)
15
15
  json (~> 1.8)
16
+ rest-client (>= 1.6.8, < 2)
16
17
  simplecov (~> 0.11.0)
17
18
  term-ansicolor (~> 1.3)
18
19
  thor (~> 0.19.1)
19
20
  tins (~> 1.6.0)
20
21
  debug_inspector (0.0.2)
21
22
  docile (1.1.5)
23
+ domain_name (0.5.20160128)
24
+ unf (>= 0.0.5, < 1.0.0)
25
+ http-cookie (1.0.2)
26
+ domain_name (~> 0.5)
22
27
  interception (0.5)
23
28
  json (1.8.3)
24
29
  lex (0.1.0)
25
30
  method_source (0.8.2)
31
+ mime-types (2.99.1)
32
+ netrc (0.11.0)
26
33
  os (0.9.6)
27
34
  pry (0.10.3)
28
35
  coderay (~> 1.1.0)
@@ -44,6 +51,10 @@ GEM
44
51
  pry-rescue
45
52
  pry-stack_explorer
46
53
  rake (10.5.0)
54
+ rest-client (1.8.0)
55
+ http-cookie (>= 1.0.2, < 2.0)
56
+ mime-types (>= 1.16, < 3.0)
57
+ netrc (~> 0.7)
47
58
  simplecov (0.11.2)
48
59
  docile (~> 1.1.0)
49
60
  json (~> 1.8)
@@ -54,6 +65,9 @@ GEM
54
65
  tins (~> 1.0)
55
66
  thor (0.19.1)
56
67
  tins (1.6.0)
68
+ unf (0.1.4)
69
+ unf_ext
70
+ unf_ext (0.0.7.2)
57
71
 
58
72
  PLATFORMS
59
73
  ruby
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Lines of Code](http://img.shields.io/badge/lines_of_code-145-brightgreen.svg?style=flat)](http://blog.codinghorror.com/the-best-code-is-no-code-at-all/)
1
+ [![Lines of Code](http://img.shields.io/badge/lines_of_code-147-brightgreen.svg?style=flat)](http://blog.codinghorror.com/the-best-code-is-no-code-at-all/)
2
2
  [![Code Status](http://img.shields.io/codeclimate/github/hopsoft/kvn.svg?style=flat)](https://codeclimate.com/github/hopsoft/kvn)
3
3
  [![Dependency Status](http://img.shields.io/gemnasium/hopsoft/kvn.svg?style=flat)](https://gemnasium.com/hopsoft/kvn)
4
4
  [![Build Status](http://img.shields.io/travis/hopsoft/kvn.svg?style=flat)](https://travis-ci.org/hopsoft/kvn)
@@ -45,3 +45,4 @@ value = "a:true; b:1; c:example; d:example with whitespace; e:null;"
45
45
  Kvn::Parser.new(value).parse
46
46
  # => {"a"=>true, "b"=>1, "c"=>"example", "d"=>"example with whitespace", "e"=>nil}
47
47
  ```
48
+
data/lib/kvn.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "lex"
1
2
  require "kvn/version"
2
3
  require "kvn/unsupported_hash_error"
3
4
  require "kvn/value_lexer"
@@ -1,5 +1,3 @@
1
- require "lex"
2
-
3
1
  module Kvn
4
2
  class Lexer < Lex::Lexer
5
3
  tokens(
@@ -4,10 +4,11 @@ module Kvn
4
4
 
5
5
  def initialize(value)
6
6
  @value = value.to_s.strip
7
+ @lexer = Kvn::Lexer.new
8
+ @value_lexer = Kvn::ValueLexer.new
7
9
  end
8
10
 
9
11
  def parse
10
- lexer = Kvn::Lexer.new
11
12
  output = lexer.lex(value)
12
13
  {}.tap do |parsed|
13
14
  begin
@@ -24,7 +25,8 @@ module Kvn
24
25
 
25
26
  if token.name == :VALUE
26
27
  raise SyntaxError.new("Empty key detected for value! <#{token.value}>") unless key_found
27
- parsed[key] = parse_value(token.value)
28
+ value_output = value_lexer.lex(token.value)
29
+ parsed[key] = value_output.next.value
28
30
  value_found = true
29
31
  key_found = false
30
32
  end
@@ -40,18 +42,7 @@ module Kvn
40
42
 
41
43
  private
42
44
 
43
- def parse_value(value)
44
- lexer = Kvn::ValueLexer.new
45
- token = lexer.lex(value).next
46
- case token.name
47
- when :NIL then value = nil
48
- when :TRUE then value = true
49
- when :FALSE then value = false
50
- when :FLOAT then value = value.to_f
51
- when :INTEGER then value = value.to_i
52
- else value.to_s
53
- end
54
- end
45
+ attr_reader :lexer, :value_lexer
55
46
 
56
47
  end
57
48
  end
@@ -1,5 +1,3 @@
1
- require "lex"
2
-
3
1
  module Kvn
4
2
  class ValueLexer < Lex::Lexer
5
3
  tokens(
@@ -11,11 +9,28 @@ module Kvn
11
9
  :STRING
12
10
  )
13
11
 
14
- rule :NIL, /null/
15
- rule :TRUE, /true/
16
- rule :FALSE, /false/
17
- rule :FLOAT, /\d+\.\d+/
18
- rule :INTEGER, /\d+/
19
- rule :STRING, /.*/
12
+ rule :NIL, /null/ do |lexer, token|
13
+ token.tap { |t| t.value = nil }
14
+ end
15
+
16
+ rule :TRUE, /true/ do |lexer, token|
17
+ token.tap { |t| t.value = true }
18
+ end
19
+
20
+ rule :FALSE, /false/ do |lexer, token|
21
+ token.tap { |t| t.value = false }
22
+ end
23
+
24
+ rule :FLOAT, /\d+\.\d+/ do |lexer, token|
25
+ token.tap { |t| t.value = t.value.to_f }
26
+ end
27
+
28
+ rule :INTEGER, /\d+/ do |lexer, token|
29
+ token.tap { |t| t.value = t.value.to_i }
30
+ end
31
+
32
+ rule :STRING, /.*/ do |lexer, token|
33
+ token.tap { |t| t.value = t.value.to_s }
34
+ end
20
35
  end
21
36
  end
@@ -1,3 +1,3 @@
1
1
  module Kvn
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kvn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-29 00:00:00.000000000 Z
11
+ date: 2016-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lex