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
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #attributes ⇒ Object
- #attributes=(value) ⇒ Object
- #group_attributes(group_name) ⇒ Object
- #inspect ⇒ Object
- #mappings ⇒ Object
- #node_name ⇒ Object
- #node_name=(value) ⇒ Object
- #relations ⇒ Object
- #should_collect? ⇒ Boolean
- #to_xml(encoding = 'UTF-8', builder = nil) ⇒ Object
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 |
#attributes ⇒ Object
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 |
#inspect ⇒ Object
202 203 204 |
# File 'lib/sax_stream/mapper.rb', line 202 def inspect "#{self.class.name}: #{attributes.inspect}" end |
#mappings ⇒ Object
223 224 225 |
# File 'lib/sax_stream/mapper.rb', line 223 def mappings self.class.mappings.values end |
#node_name ⇒ Object
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 |
#relations ⇒ Object
219 220 221 |
# File 'lib/sax_stream/mapper.rb', line 219 def relations @relations ||= build_empty_relations end |
#should_collect? ⇒ 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 |