kvn 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 487ee8d85ce8eac0225f08b86d21dd815aff1f09
4
+ data.tar.gz: 3eb23b598b95eab8155d6a3aaabfb8a1f16766c5
5
+ SHA512:
6
+ metadata.gz: 87ed111e0c4a50bcce9a9220e76c42b94ca1146ffed4d956914d26342ee041efb037e7050e9195fad1776cec93b191137174cd493451852ec656a378aedc80eb
7
+ data.tar.gz: 88e51aa82458c196d912d80c4f705d3403cb3991e0b75e50948ea2d6a6375ce7b6a1037d0bb8e77378d9debfab4214f25c5416401aeab06221b5e3af82479257
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kvn.gemspec
4
+ gemspec
@@ -0,0 +1,83 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ kvn (0.1.0)
5
+ lex (= 0.1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ binding_of_caller (0.7.2)
11
+ debug_inspector (>= 0.0.1)
12
+ byebug (8.2.2)
13
+ coderay (1.1.1)
14
+ coveralls (0.8.10)
15
+ json (~> 1.8)
16
+ rest-client (>= 1.6.8, < 2)
17
+ simplecov (~> 0.11.0)
18
+ term-ansicolor (~> 1.3)
19
+ thor (~> 0.19.1)
20
+ tins (~> 1.6.0)
21
+ debug_inspector (0.0.2)
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)
27
+ interception (0.5)
28
+ json (1.8.3)
29
+ lex (0.1.0)
30
+ method_source (0.8.2)
31
+ mime-types (2.99.1)
32
+ netrc (0.11.0)
33
+ os (0.9.6)
34
+ pry (0.10.3)
35
+ coderay (~> 1.1.0)
36
+ method_source (~> 0.8.1)
37
+ slop (~> 3.4)
38
+ pry-byebug (3.3.0)
39
+ byebug (~> 8.0)
40
+ pry (~> 0.10)
41
+ pry-rescue (1.4.2)
42
+ interception (>= 0.5)
43
+ pry
44
+ pry-stack_explorer (0.4.9.2)
45
+ binding_of_caller (>= 0.7)
46
+ pry (>= 0.9.11)
47
+ pry-test (0.6.4)
48
+ os
49
+ pry
50
+ pry-byebug
51
+ pry-rescue
52
+ pry-stack_explorer
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)
58
+ simplecov (0.11.2)
59
+ docile (~> 1.1.0)
60
+ json (~> 1.8)
61
+ simplecov-html (~> 0.10.0)
62
+ simplecov-html (0.10.0)
63
+ slop (3.6.0)
64
+ term-ansicolor (1.3.2)
65
+ tins (~> 1.0)
66
+ thor (0.19.1)
67
+ tins (1.6.0)
68
+ unf (0.1.4)
69
+ unf_ext
70
+ unf_ext (0.0.7.2)
71
+
72
+ PLATFORMS
73
+ ruby
74
+
75
+ DEPENDENCIES
76
+ bundler (~> 1.11)
77
+ coveralls
78
+ kvn!
79
+ pry-test
80
+ rake (~> 10.0)
81
+
82
+ BUNDLED WITH
83
+ 1.11.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Nathan Hopkins
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,4 @@
1
+ # KVN (kevin)
2
+
3
+ A [KVN](https://github.com/hopsoft/bighorn#kvn) parser.
4
+
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :test do
4
+ exec "bundle exec pry-test"
5
+ end
6
+
7
+ task :default => :test
@@ -0,0 +1,34 @@
1
+ require "kvn/version"
2
+ require "kvn/illegal_character_error"
3
+ require "kvn/lexer"
4
+ require "kvn/parser"
5
+
6
+ module Kvn
7
+ class << self
8
+
9
+ def parse(value)
10
+ raise ArgumentError.new("Value is not a valid KVN string!") unless valid?(value)
11
+ pairs = standardize(value).split(";")
12
+ pairs.each_with_object({}) do |pair, memo|
13
+ parts = pair.split(":")
14
+ memo[parts.first] = parts.last
15
+ end
16
+ end
17
+
18
+ def valid?(value)
19
+ value = standardize(value)
20
+ semicolon_count = value.scan(";").size
21
+ colon_count = value.scan(":").size
22
+ return false unless semicolon_count > 0
23
+ return false unless colon_count > 0
24
+ return false unless semicolon_count == colon_count
25
+ end
26
+
27
+ private
28
+
29
+ def standardize(value)
30
+ value.to_s.strip
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,4 @@
1
+ module Kvn
2
+ class IllegalCharacterError < StandardError
3
+ end
4
+ end
@@ -0,0 +1,22 @@
1
+ require "lex"
2
+
3
+ module Kvn
4
+ class Lexer < Lex::Lexer
5
+ tokens(
6
+ :KEY,
7
+ :VALUE,
8
+ :PAIRDELIM,
9
+ :PARTDELIM
10
+ )
11
+
12
+ rule :KEY, /(\w|\s)+(?=:)/
13
+ rule :VALUE, /(\w|\s)+(?=;)/
14
+ rule :PAIRDELIM, /;\s*/
15
+ rule :PARTDELIM, /:/
16
+
17
+ error do |lexer, token|
18
+ message = "Illegal character in KVN string! #{token.line}:#{token.column} #{token.value}"
19
+ raise Kvn::IllegalCharacterError.new(message)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,29 @@
1
+ module Kvn
2
+ class Parser
3
+
4
+ def parse(value)
5
+ parsed = {}
6
+ lexer = Kvn::Lexer.new
7
+ output = lexer.lex(standardize_value(value))
8
+
9
+ begin
10
+ key = nil
11
+ while output.peek
12
+ token = output.next
13
+ key = token.value if token.name == :KEY
14
+ parsed[key] = token.value if token.name == :VALUE
15
+ end
16
+ rescue StopIteration
17
+ end
18
+
19
+ parsed
20
+ end
21
+
22
+ private
23
+
24
+ def standardize_value(value)
25
+ value.to_s.strip
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module Kvn
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kvn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nathan Hopkins
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lex
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-test
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - natehop@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - Gemfile
91
+ - Gemfile.lock
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - lib/kvn.rb
96
+ - lib/kvn/illegal_character_error.rb
97
+ - lib/kvn/lexer.rb
98
+ - lib/kvn/parser.rb
99
+ - lib/kvn/version.rb
100
+ homepage: https://github.com/hopsoft/kvn
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.5.1
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: KVN (kevin) parser
124
+ test_files: []