Class: RbYAML::SafeRepresenter
Constant Summary
BaseRepresenter::BUILTIN_FUNCTION_TYPE, BaseRepresenter::CLASSOBJ_TYPE, BaseRepresenter::FUNCTION_TYPE, BaseRepresenter::INSTANCE_TYPE, BaseRepresenter::MODULE_TYPE
Instance Method Summary
collapse
add_multi_representer, add_representer, #get_classobj_bases, #initialize, #represent, #represent_data, #represent_mapping, #represent_scalar, #represent_sequence
Instance Method Details
#ignore_aliases(data) ⇒ Object
143
144
145
|
# File 'lib/rbyaml/representer.rb', line 143
def ignore_aliases(data)
data.nil? || data.__is_str || TrueClass === data || FalseClass === data || data.__is_int || Float === data
end
|
#represent_bool(data) ⇒ Object
159
160
161
162
|
# File 'lib/rbyaml/representer.rb', line 159
def represent_bool(data)
value = data ? "true" : "false"
represent_scalar('tag:yaml.org,2002:bool',value)
end
|
#represent_datetime(data) ⇒ Object
198
199
200
201
202
203
204
205
206
207
|
# File 'lib/rbyaml/representer.rb', line 198
def represent_datetime(data)
value = "%04d-%02d-%02d %02d:%02d:%02d" % [data.year, data.month, data.day, data.hour, data.min, data.sec]
if data.usec != 0
value += "." + (data.usec/1000000.0).to_s.split(/\./)[1]
end
if data.utc_offset != 0
value += data.utc_offset.to_s
end
represent_scalar(data.taguri, value)
end
|
#represent_dict(data) ⇒ Object
186
187
188
|
# File 'lib/rbyaml/representer.rb', line 186
def represent_dict(data)
represent_mapping(data.taguri, data)
end
|
#represent_float(data) ⇒ Object
168
169
170
171
172
173
174
175
176
177
178
179
|
# File 'lib/rbyaml/representer.rb', line 168
def represent_float(data)
if data.infinite? == 1
value = ".inf"
elsif data.infinite? == -1
value = "-.inf"
elsif data.nan? || data != data
value = ".nan"
else
value = data.to_s
end
represent_scalar(data.taguri, value)
end
|
#represent_int(data) ⇒ Object
164
165
166
|
# File 'lib/rbyaml/representer.rb', line 164
def represent_int(data)
represent_scalar(data.taguri,data.to_s)
end
|
#represent_list(data) ⇒ Object
181
182
183
184
|
# File 'lib/rbyaml/representer.rb', line 181
def represent_list(data)
represent_sequence(data.taguri, data)
end
|
#represent_none(data) ⇒ Object
147
148
149
|
# File 'lib/rbyaml/representer.rb', line 147
def represent_none(data)
represent_scalar(data.taguri,"null")
end
|
#represent_ruby(data) ⇒ Object
209
210
211
212
213
214
215
216
|
# File 'lib/rbyaml/representer.rb', line 209
def represent_ruby(data)
state = data.to_yaml_properties
map = {}
state.each do |m|
map[m[1..-1]] = data.instance_variable_get(m)
end
represent_mapping("!ruby/object:#{data.class.yaml_tag_class_name}", map,nil)
end
|
#represent_set(data) ⇒ Object
190
191
192
193
194
195
196
|
# File 'lib/rbyaml/representer.rb', line 190
def represent_set(data)
value = {}
for key in data
value[key] = nil
end
represent_mapping(data.taguri, value)
end
|
#represent_str(data) ⇒ Object
151
152
153
|
# File 'lib/rbyaml/representer.rb', line 151
def represent_str(data)
represent_scalar(data.taguri,data,nil)
end
|
#represent_symbol(data) ⇒ Object
155
156
157
|
# File 'lib/rbyaml/representer.rb', line 155
def represent_symbol(data)
represent_scalar(data.taguri,data.to_s)
end
|
#represent_undefined(data) ⇒ Object
227
228
229
|
# File 'lib/rbyaml/representer.rb', line 227
def represent_undefined(data)
raise RepresenterError.new("cannot represent an object: #{data}")
end
|
#represent_yaml_object(tag, data, flow_style = nil) ⇒ Object
218
219
220
221
222
223
224
225
|
# File 'lib/rbyaml/representer.rb', line 218
def represent_yaml_object(tag, data, flow_style=nil)
state = data.to_yaml_properties
map = {}
state.each do |m|
map[m[1..-1]] = data.instance_variable_get(m)
end
represent_mapping(tag, map, flow_style)
end
|