Class: Atom::Xml::Parseable::ParseSpec
- Inherits:
-
Object
- Object
- Atom::Xml::Parseable::ParseSpec
- Defined in:
- lib/atom/xml/parser.rb
Overview
Contains the specification for how an element should be parsed.
This should not need to be constructed directly, instead use the element and elements macros in the declaration of the class.
See Parseable.
Instance Attribute Summary (collapse)
-
- (Object) attribute
readonly
:nodoc:.
-
- (Object) name
readonly
:nodoc:.
-
- (Object) options
readonly
:nodoc:.
Instance Method Summary (collapse)
-
- (ParseSpec) initialize(name, options = {})
constructor
A new instance of ParseSpec.
-
- (Object) parse(target, xml)
Parses a chunk of XML according the specification.
- - (Boolean) single?
Constructor Details
- (ParseSpec) initialize(name, options = {})
A new instance of ParseSpec
354 355 356 357 358 |
# File 'lib/atom/xml/parser.rb', line 354 def initialize(name, = {}) @name = name.to_s @attribute = Atom.to_attrname(name) @options = end |
Instance Attribute Details
- (Object) attribute (readonly)
:nodoc:
352 353 354 |
# File 'lib/atom/xml/parser.rb', line 352 def attribute @attribute end |
- (Object) name (readonly)
:nodoc:
352 353 354 |
# File 'lib/atom/xml/parser.rb', line 352 def name @name end |
- (Object) options (readonly)
:nodoc:
352 353 354 |
# File 'lib/atom/xml/parser.rb', line 352 def @options end |
Instance Method Details
- (Object) parse(target, xml)
Parses a chunk of XML according the specification. The data extracted will be assigned to the target object.
363 364 365 366 367 368 369 370 371 372 |
# File 'lib/atom/xml/parser.rb', line 363 def parse(target, xml) case [:type] when :single target.send("#{@attribute}=".to_sym, build(target, xml)) when :collection collection = target.send(@attribute.to_s) element = build(target, xml) collection << element end end |
- (Boolean) single?
374 375 376 |
# File 'lib/atom/xml/parser.rb', line 374 def single? [:type] == :single end |