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


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

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

Instance Method Details

#[](key) ⇒ Object


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

def [](key)
  attributes[key]
end

#[]=(key, value) ⇒ Object


180
181
182
# File 'lib/sax_stream/mapper.rb', line 180

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

#attributesObject


192
193
194
# File 'lib/sax_stream/mapper.rb', line 192

def attributes
  @attributes ||= {}
end

#attributes=(value) ⇒ Object


196
197
198
# File 'lib/sax_stream/mapper.rb', line 196

def attributes=(value)
  @attributes = value
end

#group_attributes(group_name) ⇒ Object


200
201
202
203
# File 'lib/sax_stream/mapper.rb', line 200

def group_attributes(group_name)
  keys = self.class.group_keys(group_name).map(&:to_s)
  attributes.reject {|key, value| !keys.include?(key) }
end

#inspectObject


188
189
190
# File 'lib/sax_stream/mapper.rb', line 188

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

#mappingsObject


209
210
211
# File 'lib/sax_stream/mapper.rb', line 209

def mappings
  self.class.mappings.values
end

#node_nameObject


213
214
215
# File 'lib/sax_stream/mapper.rb', line 213

def node_name
  @node_name || self.class.node_name
end

#node_name=(value) ⇒ Object


217
218
219
# File 'lib/sax_stream/mapper.rb', line 217

def node_name=(value)
  @node_name = value
end

#relationsObject


205
206
207
# File 'lib/sax_stream/mapper.rb', line 205

def relations
  @relations ||= build_empty_relations
end

#should_collect?Boolean

Returns:

  • (Boolean)

221
222
223
# File 'lib/sax_stream/mapper.rb', line 221

def should_collect?
  self.class.should_collect?
end

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


225
226
227
228
# File 'lib/sax_stream/mapper.rb', line 225

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