module TINCheck::XML::Serializer
Constants
- ATTRIBUTES
Attributes
attributes[R]
Public Class Methods
coerce(type, obj = nil, &blk)
click to toggle source
# File lib/tincheck/xml/serializer.rb, line 15 def self.coerce(type, obj = nil, &blk) raise TypeError, '`type` must be a `Class`' unless type.is_a?(Class) obj ||= blk raise TypeError, '`obj` must respond to `call`' unless obj.respond_to?(:call) @@type_coercions[type] = obj end
new(attributes: ATTRIBUTES)
click to toggle source
# File lib/tincheck/xml/serializer.rb, line 24 def initialize(attributes: ATTRIBUTES) @attributes = attributes end
Private Instance Methods
add_xml_elements!(parent, obj)
click to toggle source
# File lib/tincheck/xml/serializer.rb, line 30 def add_xml_elements!(parent, obj) case obj when Hash obj.each { |k, v| attributes_or_elements!(parent, k, v) } when Array obj.each { |v| add_xml_elements!(parent, v) } else insert_text!(parent, obj) end parent end
text_with(obj)
click to toggle source
# File lib/tincheck/xml/serializer.rb, line 42 def text_with(obj) (callable = @@type_coercions[obj.class]) ? callable.call(obj) : obj.to_s end