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



198
199
200
# File 'lib/sax_stream/mapper.rb', line 198

def [](key)
  attributes[key]
end

#[]=(key, value) ⇒ Object



194
195
196
# File 'lib/sax_stream/mapper.rb', line 194

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

#attributesObject



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

def attributes
  @attributes ||= {}
end

#attributes=(value) ⇒ Object



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

def attributes=(value)
  @attributes = value
end

#group_attributes(group_name) ⇒ Object



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

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

#inspectObject



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

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

#mappingsObject



223
224
225
# File 'lib/sax_stream/mapper.rb', line 223

def mappings
  self.class.mappings.values
end

#node_nameObject



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

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

#node_name=(value) ⇒ Object



231
232
233
# File 'lib/sax_stream/mapper.rb', line 231

def node_name=(value)
  @node_name = value
end

#relationsObject



219
220
221
# File 'lib/sax_stream/mapper.rb', line 219

def relations
  @relations ||= build_empty_relations
end

#should_collect?Boolean

Returns:

  • (Boolean)


235
236
237
# File 'lib/sax_stream/mapper.rb', line 235

def should_collect?
  self.class.should_collect?
end

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



239
240
241
242
# File 'lib/sax_stream/mapper.rb', line 239

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