Class: EbayTrader::XMLBuilder
- Inherits:
-
Object
- Object
- EbayTrader::XMLBuilder
- Defined in:
- lib/ebay_trader/xml_builder.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#depth ⇒ Object
readonly
Returns the value of attribute depth.
-
#tab_width ⇒ Object
readonly
Returns the value of attribute tab_width.
-
#xml ⇒ Object
readonly
Returns the value of attribute xml.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ XMLBuilder
constructor
A new instance of XMLBuilder.
-
#method_missing(method_name, *args, &block) ⇒ Object
Catch-all method to avoid having to create individual methods for each XML tag name.
-
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Only respond to method names with only numbers and letters.
-
#root(name, *args, &block) ⇒ Object
Begin creating an XML string by specifying the root node.
Constructor Details
#initialize(args = {}) ⇒ XMLBuilder
Returns a new instance of XMLBuilder.
8 9 10 11 12 |
# File 'lib/ebay_trader/xml_builder.rb', line 8 def initialize(args = {}) @xml = '' @depth = 0 @tab_width = (args[:tab_width] || 0).to_i end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
Catch-all method to avoid having to create individual methods for each XML tag name.
15 16 17 18 19 20 21 |
# File 'lib/ebay_trader/xml_builder.rb', line 15 def method_missing(method_name, *args, &block) if @context && @context.respond_to?(method_name) @context.send(method_name, *args, &block) else node(method_name, args, &block) end end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
6 7 8 |
# File 'lib/ebay_trader/xml_builder.rb', line 6 def context @context end |
#depth ⇒ Object (readonly)
Returns the value of attribute depth.
6 7 8 |
# File 'lib/ebay_trader/xml_builder.rb', line 6 def depth @depth end |
#tab_width ⇒ Object (readonly)
Returns the value of attribute tab_width.
6 7 8 |
# File 'lib/ebay_trader/xml_builder.rb', line 6 def tab_width @tab_width end |
#xml ⇒ Object (readonly)
Returns the value of attribute xml.
6 7 8 |
# File 'lib/ebay_trader/xml_builder.rb', line 6 def xml @xml end |
Instance Method Details
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Only respond to method names with only numbers and letters. Do not respond to names with underscores.
25 26 27 |
# File 'lib/ebay_trader/xml_builder.rb', line 25 def respond_to_missing?(method_name, include_private = false) super || method_name.to_s =~ /^[a-z0-9]+$/i end |
#root(name, *args, &block) ⇒ Object
Begin creating an XML string by specifying the root node. This also sets the context scope, allowing methods and variables outside the block to be accessed.
36 37 38 39 |
# File 'lib/ebay_trader/xml_builder.rb', line 36 def root(name, *args, &block) set_context(&block) node(name, args, &block) end |