class Pasta::Recipes::Base
Public Instance Methods
method_missing(method, *args, &block)
click to toggle source
Public. Generic to_x parser that converts a string to the specified output format.
Uses a depth first strategy to parse a text according to incredient rules as defined in a grammar Raises a Pasta::Error if a grammar has not been defined
text - a String to be parsed
Example
to_html('some yummy text') # => '<p>some yummy text</p>'
Returns a String
Calls superclass method
# File lib/pasta/recipes/base.rb, line 20 def method_missing(method, *args, &block) if method.to_s =~ /^to_(.+)$/ # ensure a grammar has been defined raise Pasta::Error.new "A grammar for #{$1} has not been defined in recipe #{self.class.name}" if grammars($1.to_sym).nil? # Depth first parsing - each ingredient should accept and return an input and output input, output = args[0], '' while input != "" do grammars($1.to_sym).each do |rule| input, output = send(rule, input, output) end end output.strip # remove any trailing whitespace else super end end