vdf 0.1.0 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 32e8e30f4e6373a5dc4ccebbcad8b772ecb61ee33c5569fea8fe847be14554a9
4
- data.tar.gz: 178a3988d3a942959aa020a7ae3b03a954173b07ccd366927e661af4608744c3
3
+ metadata.gz: d5d8ae39f6072432cdfe4d3dfb87a7796b8bd7a5d369f758a5acb97843bad326
4
+ data.tar.gz: d73ca1c7447c822df43658494b712020131346e371feeba2a16b86dc0e343cf6
5
5
  SHA512:
6
- metadata.gz: 8074d9085c25209f16f9d6e483282a2d7c775170b3f099666bc34ef1dfe69025dbbbafc2743619853b1293252ec059898a24deedcb8fa5dc73410742317833af
7
- data.tar.gz: d4096efae25a923160aa2ddfb99bee79cebd363bfaee906d44be367a4ceec53bed72ff8157c46038ba926ef0f2196297ffe77a48933b5c750882004f6f634574
6
+ metadata.gz: 354f55eb0fbefcfd5ff18a2d89f175b9b971ebaea1374e38c9628aaeabbb7425fbb2e4960f7914716a7a6b25e4b3155f8e681c7c0d7a65b89eb25388a7c819c9
7
+ data.tar.gz: 1e5db532c4eb45426173471aaf390060bdd6f8a59225356db6a64315aaa57e06dd95700d5f231387ee3024caec90d8ebf17c1f89ab9efd4bc713933ed3950d11
@@ -0,0 +1,32 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - master
7
+ push:
8
+ branches:
9
+ - master
10
+
11
+ jobs:
12
+ build:
13
+ name: Build + Publish
14
+ runs-on: ubuntu-latest
15
+
16
+ steps:
17
+ - uses: actions/checkout@master
18
+ - name: Set up Ruby 2.6
19
+ uses: actions/setup-ruby@v1
20
+ with:
21
+ version: 2.6.x
22
+
23
+ - name: Publish to RubyGems
24
+ run: |
25
+ mkdir -p $HOME/.gem
26
+ touch $HOME/.gem/credentials
27
+ chmod 0600 $HOME/.gem/credentials
28
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
29
+ gem build *.gemspec
30
+ gem push *.gem
31
+ env:
32
+ GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Vdf
1
+ # VDF
2
2
 
3
- VDF is a gem to convert Valve's KeyValue format to ruby hashes and back, based on the excellent https://github.com/node-steam/vdf
3
+ VDF is a gem to convert Valve's KeyValue format to ruby hashes and back, based on the excellent [node-steam/vdf](https://github.com/node-steam/vdf)
4
4
 
5
5
  ## Installation
6
6
 
@@ -20,7 +20,7 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- Parsing a VDF is simple:
23
+ Parsing a VDF file is simple:
24
24
 
25
25
  ```ruby
26
26
  require "vdf"
@@ -36,20 +36,53 @@ p parsed
36
36
 
37
37
  ```
38
38
 
39
+ Creating one is too:
40
+
41
+ ```ruby
42
+ require "vdf"
43
+
44
+ # Set up hash to generate a VDF from
45
+ object = {
46
+ "string" => "string",
47
+ "false" => false,
48
+ "true" => true,
49
+ "number" => 1234,
50
+ "float" => 12.34,
51
+ "null" => nil,
52
+ "nested" => {
53
+ "string" => "string",
54
+ "deep" => {
55
+ "string" => "string"
56
+ }
57
+ }
58
+ }
59
+
60
+ # Generate a VDF string and output it
61
+ puts VDF.generate(object)
62
+
63
+ ```
64
+
39
65
  ## Performance comparison
40
66
 
41
67
  Small VDF File
42
68
  ```
43
- user system total real
44
- vdf4r 0.391000 0.000000 0.391000 ( 0.383975)
45
- vdf 0.016000 0.000000 0.016000 ( 0.012664)
69
+ user system total real
70
+ vdf 0.015000 0.000000 0.015000 ( 0.013349)
71
+ vdf4r 0.391000 0.000000 0.391000 ( 0.389993)
72
+ ```
73
+
74
+ Large VDF File (4MB - CS:GO's items_game.txt)
75
+ ```
76
+ user system total real
77
+ vdf 1.312000 0.031000 1.343000 ( 1.348015)
78
+ vdf4r 53.422000 0.016000 53.438000 ( 54.020029)
46
79
  ```
47
80
 
48
- Large VDF File (CS:GO's items_game.txt)
81
+ Compared to the [vdf4r gem](https://github.com/skadistats/vdf4r) using [this script](https://gist.github.com/sapphyrus/3aab81ad06949c3743ad91e20ccf7c65).
49
82
 
50
83
  ## Contributing
51
84
 
52
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/vdf.
85
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sapphyrus/vdf.
53
86
 
54
87
  ## License
55
88
 
data/lib/vdf/generate.rb CHANGED
@@ -1,32 +1,32 @@
1
- module VDF
2
- class Generator
3
- class << self
4
-
5
- def generate(object)
6
- generate_impl(object, 0)
7
- end
8
-
9
- private
10
-
11
- def generate_impl(object, level)
12
- result = ""
13
- indent = -"\t"*level
14
-
15
- object.each do |key, value|
16
- if value.respond_to? :each
17
- result << [indent, -'"', key, -"\"\n", indent, -"{\n", generate_impl(value, level + 1), indent, -"}\n"].join
18
- else
19
- result << [indent, -'"', key, -'"', indent, indent, -'"', value.to_s, -"\"\n"].join
20
- end
21
- end
22
-
23
- result
24
- end
25
- end
26
- end
27
-
28
- def generate(object)
29
- Generator.generate(object)
30
- end
31
- module_function :generate
32
- end
1
+ module VDF
2
+ class Generator
3
+ class << self
4
+
5
+ def generate(object)
6
+ generate_impl(object, 0)
7
+ end
8
+
9
+ private
10
+
11
+ def generate_impl(object, level)
12
+ result = ""
13
+ indent = -"\t"*level
14
+
15
+ object.each do |key, value|
16
+ if value.respond_to? :each
17
+ result << [indent, -'"', key, -"\"\n", indent, -"{\n", generate_impl(value, level + 1), indent, -"}\n"].join
18
+ else
19
+ result << [indent, -'"', key, -'"', indent, indent, -'"', value.to_s, -"\"\n"].join
20
+ end
21
+ end
22
+
23
+ result
24
+ end
25
+ end
26
+ end
27
+
28
+ def generate(object)
29
+ Generator.generate(object)
30
+ end
31
+ module_function :generate
32
+ end
data/lib/vdf/parse.rb CHANGED
@@ -1,96 +1,96 @@
1
- module VDF
2
- class Parser
3
- class << self
4
- REGEX = Regexp.new(
5
- '^("((?:\\\\.|[^\\\\"])+)"|([a-z0-9\\-\\_]+))' +
6
- '([ \t]*(' +
7
- '"((?:\\\\.|[^\\\\"])*)(")?' +
8
- '|([a-z0-9\\-\\_]+)' +
9
- '))?',
10
- Regexp::MULTILINE
11
- )
12
-
13
- def parse(text)
14
- lines = text.lines
15
- object = {}
16
- stack = [object]
17
- expect = false
18
- skip_lines = 0
19
-
20
- lines.each_with_index do |line, i|
21
- if skip_lines > 0
22
- skip_lines -= 1
23
- next
24
- end
25
-
26
- line.strip!
27
- next if line == -'' || line[0] == -'/'
28
-
29
- if line.start_with?(-'{')
30
- expect = false
31
- next
32
- elsif expect
33
- raise ParserError, "Invalid syntax on line #{i+1} (1)"
34
- end
35
-
36
- if line.start_with?(-'}')
37
- stack.pop
38
- next
39
- end
40
-
41
- loop do
42
- m = REGEX.match(line)
43
- if m.nil?
44
- raise ParserError, "Invalid syntax on line #{i+1} (2)"
45
- end
46
-
47
- key = m[2] || m[3]
48
- val = m[6] || m[8]
49
-
50
- if val.nil?
51
- if stack[-1][key].nil?
52
- stack[-1][key] = {}
53
- end
54
- stack.push(stack[-1][key])
55
- expect = true
56
- else
57
- if m[7].nil? && m[8].nil?
58
- line << -"\n" << lines[i+skip_lines+1].chomp
59
- skip_lines += 1
60
- next
61
- end
62
-
63
- stack[stack.length - 1][key] = begin
64
- begin
65
- Integer(val)
66
- rescue ArgumentError
67
- Float(val)
68
- end
69
- rescue ArgumentError
70
- case val.downcase
71
- when -"true"
72
- true
73
- when -"false"
74
- false
75
- when -"null"
76
- nil
77
- else
78
- val
79
- end
80
- end
81
- end
82
-
83
- break
84
- end
85
- end
86
-
87
- return object
88
- end
89
- end
90
- end
91
-
92
- def parse(text)
93
- Parser.parse(text)
94
- end
95
- module_function :parse
96
- end
1
+ module VDF
2
+ class Parser
3
+ class << self
4
+ REGEX = Regexp.new(
5
+ '^("((?:\\\\.|[^\\\\"])+)"|([a-z0-9\\-\\_]+))' +
6
+ '([ \t]*(' +
7
+ '"((?:\\\\.|[^\\\\"])*)(")?' +
8
+ '|([a-z0-9\\-\\_]+)' +
9
+ '))?',
10
+ Regexp::MULTILINE
11
+ )
12
+
13
+ def parse(text)
14
+ lines = text.lines
15
+ object = {}
16
+ stack = [object]
17
+ expect = false
18
+ skip_lines = 0
19
+
20
+ lines.each_with_index do |line, i|
21
+ if skip_lines > 0
22
+ skip_lines -= 1
23
+ next
24
+ end
25
+
26
+ line.strip!
27
+ next if line == -'' || line[0] == -'/'
28
+
29
+ if line.start_with?(-'{')
30
+ expect = false
31
+ next
32
+ elsif expect
33
+ raise ParserError, "Invalid syntax on line #{i+1} (1)"
34
+ end
35
+
36
+ if line.start_with?(-'}')
37
+ stack.pop
38
+ next
39
+ end
40
+
41
+ loop do
42
+ m = REGEX.match(line)
43
+ if m.nil?
44
+ raise ParserError, "Invalid syntax on line #{i+1} (2)"
45
+ end
46
+
47
+ key = m[2] || m[3]
48
+ val = m[6] || m[8]
49
+
50
+ if val.nil?
51
+ if stack[-1][key].nil?
52
+ stack[-1][key] = {}
53
+ end
54
+ stack.push(stack[-1][key])
55
+ expect = true
56
+ else
57
+ if m[7].nil? && m[8].nil?
58
+ line << -"\n" << lines[i+skip_lines+1].chomp
59
+ skip_lines += 1
60
+ next
61
+ end
62
+
63
+ stack[stack.length - 1][key] = begin
64
+ begin
65
+ Integer(val)
66
+ rescue ArgumentError
67
+ Float(val)
68
+ end
69
+ rescue ArgumentError
70
+ case val.downcase
71
+ when -"true"
72
+ true
73
+ when -"false"
74
+ false
75
+ when -"null"
76
+ nil
77
+ else
78
+ val
79
+ end
80
+ end
81
+ end
82
+
83
+ break
84
+ end
85
+ end
86
+
87
+ return object
88
+ end
89
+ end
90
+ end
91
+
92
+ def parse(text)
93
+ Parser.parse(text)
94
+ end
95
+ module_function :parse
96
+ end
data/lib/vdf/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module VDF
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0"
3
3
  end
data/vdf.gemspec CHANGED
@@ -5,7 +5,7 @@ require "vdf/version"
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "vdf"
7
7
  spec.version = VDF::VERSION
8
- spec.authors = ["Phil"]
8
+ spec.authors = ["sapphyrus"]
9
9
  spec.email = ["phil5686@gmail.com"]
10
10
 
11
11
  spec.summary = %q{Parses Valve's KeyValue format to Ruby Hashes and back}
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Phil
7
+ - sapphyrus
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
@@ -31,16 +31,14 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
+ - ".github/workflows/gempush.yml"
34
35
  - ".gitignore"
35
- - Gemfile
36
- - Gemfile.lock
37
36
  - LICENSE.txt
38
37
  - README.md
39
38
  - lib/vdf.rb
40
39
  - lib/vdf/generate.rb
41
40
  - lib/vdf/parse.rb
42
41
  - lib/vdf/version.rb
43
- - test.rb
44
42
  - vdf.gemspec
45
43
  homepage: https://github.com/sapphyrus/vdf
46
44
  licenses:
@@ -63,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
61
  - !ruby/object:Gem::Version
64
62
  version: '0'
65
63
  requirements: []
66
- rubygems_version: 3.0.4
64
+ rubygems_version: 3.0.3
67
65
  signing_key:
68
66
  specification_version: 4
69
67
  summary: Parses Valve's KeyValue format to Ruby Hashes and back
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in vdf.gemspec
4
- gemspec
data/Gemfile.lock DELETED
@@ -1,18 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- vdf (0.1.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
-
10
- PLATFORMS
11
- x64-mingw32
12
-
13
- DEPENDENCIES
14
- bundler (~> 2.0)
15
- vdf!
16
-
17
- BUNDLED WITH
18
- 2.0.2
data/test.rb DELETED
@@ -1,5 +0,0 @@
1
- require "pry"
2
- require "bundler/setup"
3
- require "vdf"
4
-
5
- binding.pry