Class: AWS::Core::XML::Grammar
- Inherits:
-
Object
- Object
- AWS::Core::XML::Grammar
- Defined in:
- lib/aws/core/xml/grammar.rb
Overview
A class that simplifies building XML Parser rules. This is also a compatability layer between the old and new formats of the api config.
Instance Attribute Summary collapse
-
#rules ⇒ Hash
readonly
Returns a hash of rules defined by this grammar.
Class Method Summary collapse
Instance Method Summary collapse
-
#customize(customizations = nil, &block) ⇒ Grammar
Returns a new grammar (leaving the current one un-modified) with the given customizations applied.
-
#customize!(customizations = nil, &block) ⇒ Object
Applies customizations to the current grammar, not returning a new grammar.
-
#initialize(rules = {}, options = {}) ⇒ Grammar
constructor
A new instance of Grammar.
-
#parse(xml) ⇒ Data
Parses the XML with the rules provided by the current grammar.
Constructor Details
#initialize(rules = {}, options = {}) ⇒ Grammar
Returns a new instance of Grammar.
23 24 25 26 27 28 29 |
# File 'lib/aws/core/xml/grammar.rb', line 23 def initialize rules = {}, = {} @rules = rules @context = @rules @element_name = 'xml' @inflect_rename = .key?(:inflect_rename) ? [:inflect_rename] : true end |
Instance Attribute Details
#rules ⇒ Hash (readonly)
Returns a hash of rules defined by this grammar.
41 42 43 |
# File 'lib/aws/core/xml/grammar.rb', line 41 def rules @rules end |
Class Method Details
.customize(customizations = nil, rules = {}, opts = {}, &block) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/aws/core/xml/grammar.rb', line 76 def self.customize customizations = nil, rules = {}, opts = {}, &block grammar = self.new(deep_copy(rules), opts) grammar.send(:apply_customizations, customizations) if customizations grammar.instance_eval(&block) if block_given? grammar end |
.parse(xml) ⇒ Object
83 84 85 |
# File 'lib/aws/core/xml/grammar.rb', line 83 def self.parse xml self.new.parse(xml) end |
Instance Method Details
#customize(customizations = nil, &block) ⇒ Grammar
Returns a new grammar (leaving the current one un-modified) with the given customizations applied. Customizations can be given in a hash-form or in a block form.
63 64 65 66 |
# File 'lib/aws/core/xml/grammar.rb', line 63 def customize customizations = nil, &block opts = { :inflect_rename => @inflect_rename } self.class.customize(customizations, @rules, opts, &block) end |
#customize!(customizations = nil, &block) ⇒ Object
Applies customizations to the current grammar, not returning a new grammar.
70 71 72 73 74 |
# File 'lib/aws/core/xml/grammar.rb', line 70 def customize! customizations = nil, &block apply_customizations(customizations) if customizations instance_eval(&block) if block_given? self end |
#parse(xml) ⇒ Data
Parses the XML with the rules provided by the current grammar. This method is meant to provide backwards compatability with the old XmlGrammar class that handled rules and parsing.
36 37 38 |
# File 'lib/aws/core/xml/grammar.rb', line 36 def parse xml Data.new(Parser.parse(xml, rules)) end |