Module: SaxStream::Mapper

Defined in:
lib/sax_stream/mapper.rb

Overview

Include this module to make your class map an XML node. For usage examples, see the READEME.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



8
9
10
# File 'lib/sax_stream/mapper.rb', line 8

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#[](key) ⇒ Object



150
151
152
# File 'lib/sax_stream/mapper.rb', line 150

def [](key)
  attributes[key]
end

#[]=(key, value) ⇒ Object



146
147
148
# File 'lib/sax_stream/mapper.rb', line 146

def []=(key, value)
  attributes[key] = value
end

#attributesObject



158
159
160
# File 'lib/sax_stream/mapper.rb', line 158

def attributes
  @attributes ||= {}
end

#attributes=(value) ⇒ Object



162
163
164
# File 'lib/sax_stream/mapper.rb', line 162

def attributes=(value)
  @attributes = value
end

#inspectObject



154
155
156
# File 'lib/sax_stream/mapper.rb', line 154

def inspect
  "#{self.class.name}: #{attributes.inspect}"
end

#mappingsObject



170
171
172
# File 'lib/sax_stream/mapper.rb', line 170

def mappings
  self.class.mappings.values
end

#node_nameObject



174
175
176
# File 'lib/sax_stream/mapper.rb', line 174

def node_name
  self.class.node_name
end

#relationsObject



166
167
168
# File 'lib/sax_stream/mapper.rb', line 166

def relations
  @relations ||= build_empty_relations
end

#should_collect?Boolean

Returns:

  • (Boolean)


178
179
180
# File 'lib/sax_stream/mapper.rb', line 178

def should_collect?
  self.class.should_collect?
end

#to_xml(encoding = 'UTF-8', builder = nil) ⇒ Object



182
183
184
185
# File 'lib/sax_stream/mapper.rb', line 182

def to_xml(encoding = 'UTF-8', builder = nil)
  builder ||= Internal::XmlBuilder.new(:encoding => encoding)
  builder.build_xml_for(self)
end