jsondoc 0.0.3 → 0.0.4
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/CHANGELOG.md +18 -0
- data/{MIT-LICENSE → LICENSE} +0 -0
- data/VERSION +1 -1
- data/jsondoc.gemspec +5 -5
- data/lib/jsondoc/document.rb +39 -19
- metadata +4 -4
- data/CHANGELOG +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a67112a09bdcadf7b01a4da9f764afcc2b997718
|
4
|
+
data.tar.gz: c16488cb845e829d9d40b1bce7ebc7ee136219dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f81b7d01dd4ae7d0b9eb27913fcd726ef1ed09b1283673dccda60858a348e5caa60fdee3cb9a960f6cda8755f4f47246f31b84815d76399986b721111f2cb67
|
7
|
+
data.tar.gz: 5a6fef198638b13bfedceb507f33459aed78353179763f928f171be7429358f8625b058d03a08d5ea11ca9ac6a6ca868d35569cd48b4b11af8647dcce64da8a2
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
CHANGELOG
|
2
|
+
---------
|
3
|
+
- **2014-03-16**: 0.0.4
|
4
|
+
- Changed Attr methods to Prop methods to represent JSON schema property
|
5
|
+
- Added Attr methods as aliases
|
6
|
+
- Added ability to load initial values hash
|
7
|
+
- Added key validation for #getProp() in strict mode
|
8
|
+
- Added attr_accessor for bIsStrict
|
9
|
+
- #push(Prop\Attr) will now only act on arrays
|
10
|
+
|
11
|
+
- **2014-02-12**: 0.0.3
|
12
|
+
- Added cpAttr() method
|
13
|
+
|
14
|
+
- **2014-01-31**: 0.0.2
|
15
|
+
- README bugfix
|
16
|
+
|
17
|
+
- **2014-01-28**: 0.0.1
|
18
|
+
- Initial release
|
data/{MIT-LICENSE → LICENSE}
RENAMED
File without changes
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/jsondoc.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'jsondoc'
|
3
|
-
s.version = '0.0.
|
4
|
-
s.date = '2014-
|
3
|
+
s.version = '0.0.4'
|
4
|
+
s.date = '2014-03-16'
|
5
5
|
s.summary = 'JsonDoc'
|
6
6
|
s.description = 'A base document object'
|
7
7
|
s.authors = ['John Wang']
|
8
8
|
s.email = 'john@johnwang.com'
|
9
9
|
s.files = [
|
10
|
-
'CHANGELOG',
|
11
|
-
'
|
10
|
+
'CHANGELOG.md',
|
11
|
+
'LICENSE',
|
12
12
|
'README.rdoc',
|
13
13
|
'Rakefile',
|
14
14
|
'VERSION',
|
@@ -19,4 +19,4 @@ Gem::Specification.new do |s|
|
|
19
19
|
]
|
20
20
|
s.homepage = 'http://johnwang.com/'
|
21
21
|
s.license = 'MIT'
|
22
|
-
end
|
22
|
+
end
|
data/lib/jsondoc/document.rb
CHANGED
@@ -3,11 +3,14 @@ require 'json'
|
|
3
3
|
module JsonDoc
|
4
4
|
class Document
|
5
5
|
|
6
|
-
|
6
|
+
attr_accessor :bIsStrict
|
7
|
+
|
8
|
+
def initialize(dValues=nil,dSchema=nil,bDefaultifyDoc=false,bIsStrict=true)
|
7
9
|
@dSchema = dSchema || self.getDefaultSchema()
|
8
10
|
@bDefaultifyDoc = bDefaultifyDoc ? true : false
|
9
11
|
@bIsStrict = bIsStrict ? true : false
|
10
12
|
@dDocument = self.getDefaultDocument()
|
13
|
+
self.loadInitialValues(dValues)
|
11
14
|
end
|
12
15
|
|
13
16
|
def getDefaultSchema()
|
@@ -32,9 +35,26 @@ module JsonDoc
|
|
32
35
|
return dDocument
|
33
36
|
end
|
34
37
|
|
35
|
-
def
|
38
|
+
def loadInitialValues(dValues=nil)
|
39
|
+
if dValues.nil?
|
40
|
+
return
|
41
|
+
elsif ! dValues.is_a?(Hash)
|
42
|
+
raise ArgumentError, 'E_INITIAL_VALUES_IS_NOT_A_HASH'
|
43
|
+
end
|
44
|
+
dValues.each do |yKey,xxVal|
|
45
|
+
self.setProp(yKey,xxVal)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def getProp(yKey=nil)
|
50
|
+
if yKey.nil?
|
51
|
+
raise ArgumentError, 'E_BAD_KEY__IS_NIL'
|
52
|
+
end
|
36
53
|
yKey = yKey.to_sym if yKey.kind_of?(String)
|
37
54
|
xxVal = @dDocument.has_key?(yKey) ? @dDocument[yKey] : nil
|
55
|
+
if xxVal.nil? && @bIsStrict
|
56
|
+
self.validateKey(yKey)
|
57
|
+
end
|
38
58
|
return xxVal
|
39
59
|
end
|
40
60
|
|
@@ -43,16 +63,18 @@ module JsonDoc
|
|
43
63
|
raise ArgumentError, "E_BAD_KEY__IS_NIL [#{yKey.to_s}]"
|
44
64
|
end
|
45
65
|
|
66
|
+
return true unless @bIsStrict
|
67
|
+
|
46
68
|
bKeyExists = @dSchema.has_key?(:properties) && @dSchema[:properties].has_key?(yKey) ? true : false
|
47
69
|
|
48
|
-
|
70
|
+
unless bKeyExists
|
49
71
|
raise ArgumentError, "E_UNKNOWN_KEY__STRICT #{yKey.to_s}"
|
50
72
|
end
|
51
73
|
|
52
74
|
return true
|
53
75
|
end
|
54
76
|
|
55
|
-
def
|
77
|
+
def setProp(yKey=nil,xxVal=nil)
|
56
78
|
yKey = yKey.to_sym if yKey.kind_of?(String)
|
57
79
|
|
58
80
|
self.validateKey(yKey)
|
@@ -60,25 +82,23 @@ module JsonDoc
|
|
60
82
|
@dDocument[yKey] = xxVal
|
61
83
|
end
|
62
84
|
|
63
|
-
def
|
85
|
+
def pushProp(yKey=nil,xxVal=nil)
|
64
86
|
yKey = yKey.to_sym if yKey.kind_of?(String)
|
65
87
|
|
66
88
|
self.validateKey(yKey)
|
67
89
|
|
68
|
-
|
69
|
-
|
70
|
-
if sType == 'array'
|
71
|
-
if @dDocument.has_key?(yKey)
|
90
|
+
if @dDocument.has_key?(yKey)
|
91
|
+
if @dDocument[yKey].kind_of?(Array)
|
72
92
|
@dDocument[yKey].push(xxVal)
|
73
93
|
else
|
74
|
-
|
94
|
+
raise RuntimeError, 'E_PROPERTY_IS_NOT_ARRAY'
|
75
95
|
end
|
76
96
|
else
|
77
|
-
@dDocument[yKey] = xxVal
|
97
|
+
@dDocument[yKey] = [xxVal]
|
78
98
|
end
|
79
99
|
end
|
80
100
|
|
81
|
-
def
|
101
|
+
def cpProp(yKeySrc=nil,yKeyDest=nil)
|
82
102
|
yKeySrc = yKeySrc.to_sym if yKeySrc.kind_of?(String)
|
83
103
|
yKeyDest = yKeyDest.to_sym if yKeyDest.kind_of?(String)
|
84
104
|
self.setAttr(yKeyDest, self.getAttr(yKeySrc))
|
@@ -86,9 +106,6 @@ module JsonDoc
|
|
86
106
|
|
87
107
|
def sortKeys()
|
88
108
|
@dDocument.keys.sort!
|
89
|
-
#dProperties = @dDocument[:properties]
|
90
|
-
#dProperties = dProperties.sort
|
91
|
-
#@dDocument[:properties] = dProperties
|
92
109
|
end
|
93
110
|
|
94
111
|
def fromJson(jDocument=nil)
|
@@ -110,11 +127,10 @@ module JsonDoc
|
|
110
127
|
return JSON.dump( self.asHash() )
|
111
128
|
end
|
112
129
|
|
113
|
-
def getValStringForProperties(aCols=nil,sDelimiter=
|
130
|
+
def getValStringForProperties(aCols=nil,sDelimiter="\t")
|
114
131
|
sDelimiter = "\t" unless sDelimiter.kind_of?(String) && sDelimiter.length>0
|
115
132
|
aVals = self.getValArrayForProperties(aCols)
|
116
133
|
sVals = aVals.join(sDelimiter)
|
117
|
-
#sVals = aVals.join("\t")
|
118
134
|
return sVals
|
119
135
|
end
|
120
136
|
|
@@ -131,11 +147,10 @@ module JsonDoc
|
|
131
147
|
return aVals
|
132
148
|
end
|
133
149
|
|
134
|
-
def getDescStringForProperties(aCols=nil,sDelimiter=
|
150
|
+
def getDescStringForProperties(aCols=nil,sDelimiter="\t")
|
135
151
|
sDelimiter = "\t" unless sDelimiter.kind_of?(String) && sDelimiter.length>0
|
136
152
|
aVals = self.getDescArrayForProperties(aCols)
|
137
153
|
sVals = aVals.join(sDelimiter)
|
138
|
-
#sVals = aVals.join("\t")
|
139
154
|
return sVals
|
140
155
|
end
|
141
156
|
|
@@ -153,5 +168,10 @@ module JsonDoc
|
|
153
168
|
return aVals
|
154
169
|
end
|
155
170
|
|
171
|
+
alias_method :setAttr , :setProp
|
172
|
+
alias_method :getAttr , :getProp
|
173
|
+
alias_method :pushAttr, :pushProp
|
174
|
+
alias_method :cpAttr , :cpProp
|
175
|
+
|
156
176
|
end
|
157
177
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsondoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Wang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A base document object
|
14
14
|
email: john@johnwang.com
|
@@ -16,8 +16,8 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
-
- CHANGELOG
|
20
|
-
-
|
19
|
+
- CHANGELOG.md
|
20
|
+
- LICENSE
|
21
21
|
- README.rdoc
|
22
22
|
- Rakefile
|
23
23
|
- VERSION
|