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
-
#attribute ⇒ Object
readonly
:nodoc:.
-
#name ⇒ Object
readonly
:nodoc:.
-
#options ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
-
#initialize(name, options = {}) ⇒ ParseSpec
constructor
A new instance of ParseSpec.
-
#parse(target, xml) ⇒ Object
Parses a chunk of XML according the specification.
- #single? ⇒ Boolean
Constructor Details
#initialize(name, options = {}) ⇒ ParseSpec
Returns a new instance of ParseSpec.
330 331 332 333 334 |
# File 'lib/atom/xml/parser.rb', line 330 def initialize(name, = {}) @name = name.to_s @attribute = name.to_s.sub(/:/, '_') @options = end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
:nodoc:
328 329 330 |
# File 'lib/atom/xml/parser.rb', line 328 def attribute @attribute end |
#name ⇒ Object (readonly)
:nodoc:
328 329 330 |
# File 'lib/atom/xml/parser.rb', line 328 def name @name end |
#options ⇒ Object (readonly)
:nodoc:
328 329 330 |
# File 'lib/atom/xml/parser.rb', line 328 def @options end |
Instance Method Details
#parse(target, xml) ⇒ Object
Parses a chunk of XML according the specification. The data extracted will be assigned to the target object.
339 340 341 342 343 344 345 346 347 348 |
# File 'lib/atom/xml/parser.rb', line 339 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 |
#single? ⇒ Boolean
350 351 352 |
# File 'lib/atom/xml/parser.rb', line 350 def single? [:type] == :single end |