Class: MasterCard::Core::Model::SmartMap
- Inherits:
-
Object
- Object
- MasterCard::Core::Model::SmartMap
show all
- Defined in:
- lib/mastercard/core/model.rb
Overview
Constant Summary
collapse
- KEY_LIST =
"list"
Instance Method Summary
collapse
Constructor Details
Returns a new instance of SmartMap.
38
39
40
41
|
# File 'lib/mastercard/core/model.rb', line 38
def initialize
@properties = Hash.new
@parentWithSquareBracket = /\[(.*)\]/
end
|
Instance Method Details
#containsKeys(key) ⇒ Object
163
164
165
166
167
168
169
170
171
172
173
|
# File 'lib/mastercard/core/model.rb', line 163
def containsKeys(key)
unless get(key).nil?
return true
end
return false
end
|
#get(key) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/mastercard/core/model.rb', line 80
def get(key)
keys = key.split(".")
keys_len = keys.length
@subProperty = @properties
count = 0
keys.each do |part_key|
count += 1
match = @parentWithSquareBracket.match(part_key)
unless match.nil?
begin
moveInList(part_key,match)
rescue
return nil
end
if count == keys_len
return @subProperty
end
else
if @subProperty.is_a?(Hash) && @subProperty.key?(part_key)
if count == keys_len return @subProperty[part_key]
else @subProperty = @subProperty[part_key]
end
else
return nil
end
end
end
end
|
#getObject ⇒ Object
151
152
153
154
|
# File 'lib/mastercard/core/model.rb', line 151
def getObject
return @properties
end
|
#set(key, value) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/mastercard/core/model.rb', line 43
def set(key,value)
keys = key.split(".")
keys_len = keys.length
@subProperty = @properties
count = 0
keys.each do |part_key|
count += 1
if count == keys_len
match = @parentWithSquareBracket.match(part_key)
if match.nil?
@subProperty[part_key] = value
else handleListTypeKeys(part_key,match,value)
end
else
createMap(part_key)
end
end
return @properties
end
|
#setAll(map) ⇒ Object
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/mastercard/core/model.rb', line 129
def setAll(map)
initialKey = ""
if map.is_a?(Array)
initialKey = KEY_LIST
end
iterateItemsAndAdd(map,initialKey)
return @properties
end
|
#size ⇒ Object
156
157
158
159
160
161
|
# File 'lib/mastercard/core/model.rb', line 156
def size
return @properties.length
end
|