Method: ESBify::Parser#parse!
- Defined in:
- lib/ESBify/parser.rb
#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 |
# 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 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 |