vdf-converter 0.0.2
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 +7 -0
- data/lib/vdf-converter.rb +28 -0
- data/lib/vdf-converter/vdf-to-yaml.rb +80 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4432fdf4ed6214df6dc2f7f8562a929cbac55c69
|
4
|
+
data.tar.gz: a703a07d9dacfbc848b63111568e9a92c3c8524d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3a44fb759400e13836a8d4b1b4c309cd82db9e1f6a9ba2ccfb2f339027b918c1cf65a430d54d2633ae98f9fc2c1495b9c5b189713d40e40b25999c67ad8ff9aa
|
7
|
+
data.tar.gz: c8dccdddbc4f1b53ec46e679b7a7541e8903c2da7b633b8f720f51a8e4bbc8e32d32b15297e6a2869311783520a181534ffa5243ce5c02011d599222ca3b69a6
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'json'
|
3
|
+
require_relative 'vdf-converter/vdf-to-yaml.rb'
|
4
|
+
|
5
|
+
class VdfConverter
|
6
|
+
|
7
|
+
def saveYAML(source, output_file)
|
8
|
+
parser = VdfToYAML.new
|
9
|
+
parser.parseToFile(source, output_file)
|
10
|
+
puts "Done"
|
11
|
+
end
|
12
|
+
|
13
|
+
#TODO
|
14
|
+
def saveXML(source, output_file)
|
15
|
+
puts "Not Implemented Yet."
|
16
|
+
end
|
17
|
+
|
18
|
+
def saveJSON(source, output_file)
|
19
|
+
puts "Generating to YAML first..."
|
20
|
+
parser = VdfToYAML.new
|
21
|
+
parser.parseToFile(source, "__tmp-vdf-converter.yml")
|
22
|
+
settings = YAML::load_file "__tmp-vdf-converter.yml"
|
23
|
+
puts "Writing YAML to JSON..."
|
24
|
+
json = JSON.pretty_generate settings
|
25
|
+
File.open(output_file, 'w') { |file| file.write(json) }
|
26
|
+
puts "Done"
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
class VdfToYAML
|
4
|
+
|
5
|
+
# Holds the indentation level
|
6
|
+
@@indentation_count = 0
|
7
|
+
|
8
|
+
# Takes a stream in (string) and puts out YAML to a file
|
9
|
+
def parseToFile(input_stream, output_file)
|
10
|
+
|
11
|
+
# Stats for coolness
|
12
|
+
t0 = Time.now
|
13
|
+
|
14
|
+
# STL scanner for the input stream
|
15
|
+
scanner = StringScanner.new(input_stream); 0
|
16
|
+
|
17
|
+
# output file as specified in parameters
|
18
|
+
yaml_file = File.open(output_file, 'w'); 0
|
19
|
+
|
20
|
+
while scanner.eos? == false
|
21
|
+
|
22
|
+
#search for a top level element
|
23
|
+
current_segment = scanner.scan(/\"[a-zA-Z0-9'_ .\-\/#\\,:!]*\"[ \n\t]*{/)
|
24
|
+
if current_segment != nil
|
25
|
+
current_segment = current_segment.tr("}{\n\r\t\"", "")
|
26
|
+
yaml_file.write(" "*@@indentation_count + current_segment + ":\n")
|
27
|
+
@@indentation_count = @@indentation_count + 1
|
28
|
+
end
|
29
|
+
|
30
|
+
# Search for a Key-Value pair
|
31
|
+
current_segment = scanner.scan(/[\s]*\"[a-zA-Z0-9'_ .\-\/#\\,:!]+\"[\s]*\"[a-zA-Z0-9'_ .\-\/#\\,:!]+\"/)
|
32
|
+
if current_segment != nil
|
33
|
+
current_segment = current_segment.rstrip.lstrip
|
34
|
+
key = current_segment.split(/\"/)
|
35
|
+
key = sanitizeInput(key)
|
36
|
+
yaml_file.write(" "*@@indentation_count + key[0] + ":\t" + key[2] + "\n")
|
37
|
+
end
|
38
|
+
|
39
|
+
# Search for an end segment
|
40
|
+
current_segment = scanner.scan(/[\s]}/)
|
41
|
+
if current_segment != nil
|
42
|
+
@@indentation_count = @@indentation_count -1
|
43
|
+
if @@indentation_count <= 0
|
44
|
+
puts "Reached Root Indentation"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
current_segment = scanner.scan_until(/[\s]/)
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
puts "Conversion Complete, Time Taken: #{Time.now - t0} Seconds"
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
#deals with inconsistencies from VDF to YAM, issues like characters in the key segment, looks like [:key, "junk", :value]
|
57
|
+
def sanitizeInput(key)
|
58
|
+
key = key.compact
|
59
|
+
key = key.reject{|element| element.empty?}
|
60
|
+
|
61
|
+
key[0] = key[0].tr('"', "")
|
62
|
+
key[2] = key[2].tr('"', "")
|
63
|
+
|
64
|
+
if key[0].include? ":"
|
65
|
+
key[0] = '"' + key[0] + '"'
|
66
|
+
elsif key[0].include? "#"
|
67
|
+
key[0] = '"' + key[0] + '"'
|
68
|
+
end
|
69
|
+
|
70
|
+
if key[2].include? ":"
|
71
|
+
key[2] = '"' + key[2] + '"'
|
72
|
+
end
|
73
|
+
if key[2][0] == "'"
|
74
|
+
key[2] = '"' + key[2] + '"'
|
75
|
+
end
|
76
|
+
|
77
|
+
return key
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vdf-converter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joshua Richardson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-04 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Takes a file or stream in the VDF format developed by valve and converts
|
14
|
+
it to alternative formats including YAML, JSON and a native hash.
|
15
|
+
email: joshua@fridayplans.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/vdf-converter.rb
|
21
|
+
- lib/vdf-converter/vdf-to-yaml.rb
|
22
|
+
homepage: https://github.com/JoshuaRichardson93/vdf-converter
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.4.5
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Gem that will convert Valve's data format to alternative formats!
|
46
|
+
test_files: []
|