vdf 1.0.3 → 1.0.5
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 +4 -4
- data/.github/dependabot.yml +12 -0
- data/.github/workflows/gempush.yml +5 -4
- data/LICENSE.txt +1 -1
- data/README.md +16 -2
- data/lib/vdf/generate.rb +7 -5
- data/lib/vdf/parse.rb +23 -14
- data/lib/vdf/version.rb +3 -1
- data/lib/vdf.rb +5 -3
- data/vdf.gemspec +20 -13
- metadata +11 -23
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5061239d0e55f0aec46fcde2f175862500ed7d5c25af67a0842e030cb97d90f7
|
|
4
|
+
data.tar.gz: 82198cb9b25f2345e450f8d2a2734ff66495b0c645512fcceb7fee8e96607c4f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bb1542c98373562ca7c23799eb3c9b5b7e0a1a6e07e3b7c4b595cefa55f51953e865eb286ba6fdd0bd60efce11e919f7844acdb110ec28e2969e71a8b72bf328
|
|
7
|
+
data.tar.gz: 7e87b0dbda7edde4a33371b907ea2cef21e6c91c3c1e30928dbf8e7e13d54270e781bbee8d09a004dffb3658144be0334c994d2c6cc8fd6f206072189927b4fa
|
|
@@ -14,11 +14,12 @@ jobs:
|
|
|
14
14
|
runs-on: ubuntu-latest
|
|
15
15
|
|
|
16
16
|
steps:
|
|
17
|
-
- uses: actions/checkout@
|
|
18
|
-
- name: Set up Ruby
|
|
19
|
-
uses:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
- name: Set up Ruby
|
|
19
|
+
uses: ruby/setup-ruby@v1
|
|
20
20
|
with:
|
|
21
|
-
version:
|
|
21
|
+
ruby-version: 3.4
|
|
22
|
+
bundler-cache: true
|
|
22
23
|
|
|
23
24
|
- name: Publish to GPR
|
|
24
25
|
run: |
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# VDF
|
|
2
2
|
|
|
3
3
|
[](https://actions-badge.atrox.dev/sapphyrus/vdf/goto)
|
|
4
|
+
[](https://github.com/sapphyrus/vdf/issues)
|
|
4
5
|
[](https://rubygems.org/gems/vdf)
|
|
5
6
|
[](https://rubydoc.info/gems/vdf)
|
|
6
|
-
[](https://github.com/sapphyrus/vdf/issues)
|
|
7
7
|
[](https://github.com/sapphyrus/vdf/blob/master/LICENSE.txt)
|
|
8
8
|
|
|
9
9
|
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)
|
|
@@ -68,6 +68,20 @@ puts VDF.generate(object)
|
|
|
68
68
|
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
+
If you're dealing with parsing large files, you should avoid loading them into memory fully. This library supports parsing a VDF file from a File object like this:
|
|
72
|
+
```ruby
|
|
73
|
+
require "vdf"
|
|
74
|
+
|
|
75
|
+
# Open the file in read mode and parse it.
|
|
76
|
+
parsed = File.open("filename.vdf", "r") do |file|
|
|
77
|
+
VDF.parse(file)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Pretty-print the result
|
|
81
|
+
p parsed
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
|
|
71
85
|
## Performance comparison
|
|
72
86
|
|
|
73
87
|
Small VDF File
|
|
@@ -92,7 +106,7 @@ The latest version of this library can be downloaded at
|
|
|
92
106
|
|
|
93
107
|
* https://rubygems.org/gems/vdf
|
|
94
108
|
|
|
95
|
-
Online Documentation
|
|
109
|
+
Online Documentation is located at
|
|
96
110
|
|
|
97
111
|
* https://www.rubydoc.info/gems/vdf
|
|
98
112
|
|
data/lib/vdf/generate.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module VDF
|
|
2
4
|
# The Generator class is responsible for generating VDF documents from input hashes.
|
|
3
5
|
# @see VDF.generate
|
|
@@ -9,7 +11,7 @@ module VDF
|
|
|
9
11
|
# @param object [Hash] the input object
|
|
10
12
|
# @return [String] the generated VDF document
|
|
11
13
|
def generate(object)
|
|
12
|
-
raise ArgumentError,
|
|
14
|
+
raise ArgumentError, 'Object has to respond to each' unless object.respond_to? :each
|
|
13
15
|
|
|
14
16
|
generate_impl(object, 0)
|
|
15
17
|
end
|
|
@@ -17,14 +19,14 @@ module VDF
|
|
|
17
19
|
private
|
|
18
20
|
|
|
19
21
|
def generate_impl(object, level)
|
|
20
|
-
result =
|
|
21
|
-
indent =
|
|
22
|
+
result = String.new
|
|
23
|
+
indent = "\t" * level
|
|
22
24
|
|
|
23
25
|
object.each do |key, value|
|
|
24
26
|
if value.respond_to? :each
|
|
25
|
-
result << [indent,
|
|
27
|
+
result << [indent, '"', key, "\"\n", indent, "{\n", generate_impl(value, level + 1), indent, "}\n"].join
|
|
26
28
|
else
|
|
27
|
-
result << [indent,
|
|
29
|
+
result << [indent, '"', key, '"', indent, indent, '"', value.to_s, "\"\n"].join
|
|
28
30
|
end
|
|
29
31
|
end
|
|
30
32
|
|
data/lib/vdf/parse.rb
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'stringio'
|
|
4
|
+
|
|
1
5
|
module VDF
|
|
2
6
|
# The Parser class is responsible for parsing a VDF document into a Ruby Hash
|
|
3
7
|
# @see VDF.parse
|
|
@@ -29,7 +33,7 @@ module VDF
|
|
|
29
33
|
# puts contents.inspect
|
|
30
34
|
# end
|
|
31
35
|
def parse(input)
|
|
32
|
-
raise ArgumentError,
|
|
36
|
+
raise ArgumentError, 'Input has to respond to :each_line or :to_str' unless input.respond_to?(:each_line) || input.respond_to?(:to_str)
|
|
33
37
|
input = StringIO.new(input) unless input.respond_to? :pos
|
|
34
38
|
|
|
35
39
|
result = {}
|
|
@@ -37,20 +41,23 @@ module VDF
|
|
|
37
41
|
expect = false
|
|
38
42
|
i = 0
|
|
39
43
|
|
|
40
|
-
enum = input.each_line
|
|
44
|
+
enum = input.each_line
|
|
41
45
|
enum.with_index do |line, _|
|
|
42
46
|
i += 1
|
|
43
|
-
line.encode!(
|
|
44
|
-
next if line.empty? || line[0] ==
|
|
47
|
+
line.encode!('UTF-8').strip!
|
|
48
|
+
next if line.empty? || line[0] == '/'
|
|
45
49
|
|
|
46
|
-
if line.start_with?(
|
|
50
|
+
if line.start_with?('{')
|
|
47
51
|
expect = false
|
|
48
52
|
next
|
|
49
53
|
elsif expect
|
|
50
|
-
raise ParserError, "Invalid syntax on line #{i+1} (Expected
|
|
54
|
+
raise ParserError, "Invalid syntax on line #{i+1} (Expected bracket)"
|
|
51
55
|
end
|
|
52
56
|
|
|
53
|
-
if line.start_with?(
|
|
57
|
+
if line.start_with?('}')
|
|
58
|
+
if stack.length == 1
|
|
59
|
+
raise ParserError, "Invalid syntax on line #{i} (Unexpected closing bracket)"
|
|
60
|
+
end
|
|
54
61
|
stack.pop
|
|
55
62
|
next
|
|
56
63
|
end
|
|
@@ -76,7 +83,7 @@ module VDF
|
|
|
76
83
|
end
|
|
77
84
|
|
|
78
85
|
i += 1
|
|
79
|
-
line <<
|
|
86
|
+
line << "\n" << next_line.to_s.encode("UTF-8").strip
|
|
80
87
|
next
|
|
81
88
|
end
|
|
82
89
|
|
|
@@ -85,14 +92,14 @@ module VDF
|
|
|
85
92
|
Integer(val)
|
|
86
93
|
rescue ArgumentError
|
|
87
94
|
Float(val)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
when
|
|
95
|
+
end
|
|
96
|
+
rescue ArgumentError
|
|
97
|
+
case val.downcase
|
|
98
|
+
when 'true'
|
|
92
99
|
true
|
|
93
|
-
when
|
|
100
|
+
when 'false'
|
|
94
101
|
false
|
|
95
|
-
when
|
|
102
|
+
when 'null'
|
|
96
103
|
nil
|
|
97
104
|
else
|
|
98
105
|
val
|
|
@@ -104,6 +111,8 @@ module VDF
|
|
|
104
111
|
end
|
|
105
112
|
end
|
|
106
113
|
|
|
114
|
+
raise ParserError, 'Open parentheses somewhere' unless stack.length == 1
|
|
115
|
+
|
|
107
116
|
return result
|
|
108
117
|
end
|
|
109
118
|
end
|
data/lib/vdf/version.rb
CHANGED
data/lib/vdf.rb
CHANGED
data/vdf.gemspec
CHANGED
|
@@ -1,26 +1,33 @@
|
|
|
1
|
-
lib = File.expand_path(
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
-
require
|
|
3
|
+
require 'vdf/version'
|
|
4
4
|
|
|
5
5
|
Gem::Specification.new do |spec|
|
|
6
|
-
spec.name =
|
|
6
|
+
spec.name = 'vdf'
|
|
7
7
|
spec.version = VDF::VERSION
|
|
8
|
-
spec.authors = [
|
|
9
|
-
spec.email = [
|
|
8
|
+
spec.authors = ['sapphyrus']
|
|
9
|
+
spec.email = ['phil5686@gmail.com']
|
|
10
10
|
|
|
11
|
-
spec.summary =
|
|
12
|
-
spec.homepage =
|
|
13
|
-
spec.license =
|
|
11
|
+
spec.summary = 'Parses Valve\'s KeyValue format to Ruby Hashes and back'
|
|
12
|
+
spec.homepage = 'https://github.com/sapphyrus/vdf'
|
|
13
|
+
spec.license = 'MIT'
|
|
14
14
|
|
|
15
|
-
spec.
|
|
16
|
-
|
|
15
|
+
spec.description = <<-EOF
|
|
16
|
+
VDF is a gem to convert Valve's KeyValue format to Ruby hashes and create a VDF string from a Ruby hash.
|
|
17
|
+
It's based on the excellent node-steam/vdf JS library and it's optimized for performance
|
|
18
|
+
EOF
|
|
19
|
+
|
|
20
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
21
|
+
spec.metadata['source_code_uri'] = 'https://github.com/sapphyrus/vdf'
|
|
22
|
+
spec.metadata['bug_tracker_uri'] = 'https://github.com/sapphyrus/vdf/issues'
|
|
23
|
+
spec.metadata['documentation_uri'] = 'https://www.rubydoc.info/gems/vdf'
|
|
24
|
+
|
|
25
|
+
spec.required_ruby_version = '>= 2.5'
|
|
17
26
|
|
|
18
27
|
# Specify which files should be added to the gem when it is released.
|
|
19
28
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
20
29
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
21
30
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
22
31
|
end
|
|
23
|
-
spec.require_paths = [
|
|
24
|
-
|
|
25
|
-
spec.add_development_dependency "bundler", "~> 2.0"
|
|
32
|
+
spec.require_paths = ['lib']
|
|
26
33
|
end
|
metadata
CHANGED
|
@@ -1,36 +1,24 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: vdf
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- sapphyrus
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
12
|
-
dependencies:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
requirements:
|
|
17
|
-
- - "~>"
|
|
18
|
-
- !ruby/object:Gem::Version
|
|
19
|
-
version: '2.0'
|
|
20
|
-
type: :development
|
|
21
|
-
prerelease: false
|
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
-
requirements:
|
|
24
|
-
- - "~>"
|
|
25
|
-
- !ruby/object:Gem::Version
|
|
26
|
-
version: '2.0'
|
|
27
|
-
description:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: |2
|
|
13
|
+
VDF is a gem to convert Valve's KeyValue format to Ruby hashes and create a VDF string from a Ruby hash.
|
|
14
|
+
It's based on the excellent node-steam/vdf JS library and it's optimized for performance
|
|
28
15
|
email:
|
|
29
16
|
- phil5686@gmail.com
|
|
30
17
|
executables: []
|
|
31
18
|
extensions: []
|
|
32
19
|
extra_rdoc_files: []
|
|
33
20
|
files:
|
|
21
|
+
- ".github/dependabot.yml"
|
|
34
22
|
- ".github/workflows/gempush.yml"
|
|
35
23
|
- ".gitignore"
|
|
36
24
|
- LICENSE.txt
|
|
@@ -46,7 +34,8 @@ licenses:
|
|
|
46
34
|
metadata:
|
|
47
35
|
homepage_uri: https://github.com/sapphyrus/vdf
|
|
48
36
|
source_code_uri: https://github.com/sapphyrus/vdf
|
|
49
|
-
|
|
37
|
+
bug_tracker_uri: https://github.com/sapphyrus/vdf/issues
|
|
38
|
+
documentation_uri: https://www.rubydoc.info/gems/vdf
|
|
50
39
|
rdoc_options: []
|
|
51
40
|
require_paths:
|
|
52
41
|
- lib
|
|
@@ -54,15 +43,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
54
43
|
requirements:
|
|
55
44
|
- - ">="
|
|
56
45
|
- !ruby/object:Gem::Version
|
|
57
|
-
version: '
|
|
46
|
+
version: '2.5'
|
|
58
47
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
48
|
requirements:
|
|
60
49
|
- - ">="
|
|
61
50
|
- !ruby/object:Gem::Version
|
|
62
51
|
version: '0'
|
|
63
52
|
requirements: []
|
|
64
|
-
rubygems_version: 3.
|
|
65
|
-
signing_key:
|
|
53
|
+
rubygems_version: 3.6.9
|
|
66
54
|
specification_version: 4
|
|
67
55
|
summary: Parses Valve's KeyValue format to Ruby Hashes and back
|
|
68
56
|
test_files: []
|