jyaml 0.0.1 → 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.
- checksums.yaml +4 -4
- data/lib/yaml2json.rb +46 -0
- metadata +9 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0ba3a5eb94f2a4f1abf21eb7e92a2982d10e2f8404eeb416dccaa627fc0d6b3f
|
|
4
|
+
data.tar.gz: a5dbe3d3cce830fff2c32f349d3837b9c88888167f75af6b27fd0240ab67dbcc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 87bd28a9d1b5649505cb8ebc383615fa9652eef4e8ea9274c2c66c2bb175c6d86747c603b555fb4c89d487060c67593a0266976b48d95e2aa1072a48cfc5cf75
|
|
7
|
+
data.tar.gz: a2198413a39dff1b3fc4657bada104d76ac78dcf7d850a897526d3ccf08670c1c7b92c4e64e01a6a67cbb6c5561d8bff6a032d540b30f26904dfa3c02131bac2
|
data/lib/yaml2json.rb
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
require 'yaml'
|
|
2
2
|
require 'json'
|
|
3
3
|
|
|
4
|
+
module JYaml
|
|
5
|
+
|
|
6
|
+
class JYaml
|
|
7
|
+
def initialize(file_name)
|
|
8
|
+
# init content from file
|
|
9
|
+
# support file type: yaml, json
|
|
10
|
+
# raise exception if file type not support
|
|
11
|
+
|
|
12
|
+
# get file extension
|
|
13
|
+
ext = File.extname(file_name)
|
|
14
|
+
|
|
15
|
+
if ext == '.yaml'
|
|
16
|
+
@content = load_yaml(file_name)
|
|
17
|
+
elsif ext == '.json'
|
|
18
|
+
@content = load_json(file_name)
|
|
19
|
+
else
|
|
20
|
+
raise ArgumentError.new("unsupport file type")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
attr_reader :content
|
|
26
|
+
|
|
27
|
+
def load_yaml(file_name)
|
|
28
|
+
return YAML.load_file(file_name)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def load_json(file_name)
|
|
32
|
+
json = JSON.create_id()
|
|
33
|
+
|
|
34
|
+
return JSON.load_file(file_name)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def to_json(save_name)
|
|
38
|
+
File.write(save_name, @content.to_json)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def to_yaml(save_name)
|
|
42
|
+
File.open(save_name, "w") do |file|
|
|
43
|
+
file.write(@content.to_yaml)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
4
50
|
# convert yaml to json
|
|
5
51
|
def convert_yaml_to_json(yaml_file, json_file, encoding)
|
|
6
52
|
configs = YAML.load_file(yaml_file)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jyaml
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sicheng Zhong
|
|
@@ -15,9 +15,15 @@ extensions: []
|
|
|
15
15
|
extra_rdoc_files: []
|
|
16
16
|
files:
|
|
17
17
|
- lib/yaml2json.rb
|
|
18
|
+
homepage: https://github.com/KeikoAyano/Jyaml
|
|
18
19
|
licenses:
|
|
19
|
-
-
|
|
20
|
-
metadata:
|
|
20
|
+
- MIT
|
|
21
|
+
metadata:
|
|
22
|
+
bug_tracker_uri: https://github.com/KeikoAyano/Jyaml/issues
|
|
23
|
+
source_code_uri: https://github.com/KeikoAyano/Jyaml
|
|
24
|
+
homepage_uri: https://github.com/KeikoAyano/Jyaml
|
|
25
|
+
documentation_uri: https://github.com/KeikoAyano/Jyaml
|
|
26
|
+
wiki_uri: https://github.com/KeikoAyano/Jyaml/wiki
|
|
21
27
|
rdoc_options: []
|
|
22
28
|
require_paths:
|
|
23
29
|
- lib
|