Class: ESBify::Parser
- Inherits:
-
Object
- Object
- ESBify::Parser
- Defined in:
- lib/ESBify/parser.rb
Overview
Instance Attribute Summary collapse
-
#expectation ⇒ Object
readonly
Returns the value of attribute expectation.
Instance Method Summary collapse
-
#behaviors ⇒ Object
After parsing contains the xml representation of all behaviors.
-
#expectations ⇒ Object
After parsing contains the xml representation of all expectations.
-
#initialize(context = {}) ⇒ Parser
constructor
A new instance of Parser.
-
#parse!(str) ⇒ Object
Parse a string of esb code.
-
#parse_file!(path) ⇒ Object
Pass a file path.
-
#strategies ⇒ Object
(also: #strategy)
After parsing contains the xml representation of the strategy.
Constructor Details
Instance Attribute Details
#expectation ⇒ Object (readonly)
Returns the value of attribute expectation.
17 18 19 |
# File 'lib/ESBify/parser.rb', line 17 def expectation @expectation end |
Instance Method Details
#behaviors ⇒ Object
After parsing contains the xml representation of all behaviors.
33 34 35 |
# File 'lib/ESBify/parser.rb', line 33 def behaviors @behavior.to_xml end |
#expectations ⇒ Object
After parsing contains the xml representation of all expectations.
28 29 30 |
# File 'lib/ESBify/parser.rb', line 28 def expectations @expectation.to_xml end |
#parse!(str) ⇒ Object
Parse a string of esb code.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ESBify/parser.rb', line 49 def parse!(str) # Remove comments str = str.split("\n").map{|l| l.split('#').first }.join("\n") # Evaluate ERB code str = Erubis::Eruby.new(str).evaluate(@context) # Split by sections str.split(/\!(?=(?:expectation|behaviou?r|strateg(?:y|ie))s?\n)/).each do |section| next if section =~ /\A\s*\z/m section.strip! m = section.match /\A!?(expectation|behaviou?r|strateg(?:y|ie))s?/ txt = str.split("\n") txt.shift txt.join("\n") case m[1] when /expectations?/ @expectation.parse! section when /behaviou?rs?/ @behavior.parse! section when /strateg(?:y|ie)s?/ @strategy.parse! section else raise ArgumentError end end end |
#parse_file!(path) ⇒ Object
Pass a file path. File will be read and parsed.
44 45 46 |
# File 'lib/ESBify/parser.rb', line 44 def parse_file!(path) parse! File.read(path) end |
#strategies ⇒ Object Also known as: strategy
After parsing contains the xml representation of the strategy.
38 39 40 |
# File 'lib/ESBify/parser.rb', line 38 def strategies @strategy.to_xml end |