Module: Braai::Matchers
Constant Summary collapse
- IterationMatcher =
/({{\s*for (\w+) in (\w+)\s*}}(.+?){{\s*\/for\s*}})/im
- ConditionalMatcher =
/({{\s*if\s*([\w\.]+)\s*}}(.*){{\s*\/if\s*}})/mi
- DefaultMatcher =
/({{\s*([\w\.]+)\s*}})/i
- RegionMatcher =
/({{\s*([\w]+)\s*}}(.*){{\s*\/([\w]+)\s*}})/mi
Instance Attribute Summary collapse
-
#fallback ⇒ Object
Returns the value of attribute fallback.
Instance Method Summary collapse
- #add_fallback(regex, handler = nil, &block) ⇒ Object
- #clear! ⇒ Object
- #map(regex, handler = nil, &block) ⇒ Object
- #matchers ⇒ Object
- #reset! ⇒ Object
- #set_defaults ⇒ Object
- #unmap(regex) ⇒ Object
Instance Attribute Details
#fallback ⇒ Object
Returns the value of attribute fallback.
3 4 5 |
# File 'lib/braai/matchers.rb', line 3 def fallback @fallback end |
Instance Method Details
#add_fallback(regex, handler = nil, &block) ⇒ Object
18 19 20 |
# File 'lib/braai/matchers.rb', line 18 def add_fallback(regex, handler=nil, &block) @fallback = { :regex => regex.to_s, :handler => handler || block } end |
#clear! ⇒ Object
26 27 28 29 |
# File 'lib/braai/matchers.rb', line 26 def clear! self.matchers.clear self.fallback = nil end |
#map(regex, handler = nil, &block) ⇒ Object
14 15 16 |
# File 'lib/braai/matchers.rb', line 14 def map(regex, handler = nil, &block) @matchers = {regex.to_s => handler || block}.merge(self.matchers) end |
#matchers ⇒ Object
10 11 12 |
# File 'lib/braai/matchers.rb', line 10 def matchers @matchers ||= reset! end |
#reset! ⇒ Object
31 32 33 34 |
# File 'lib/braai/matchers.rb', line 31 def reset! @matchers = {} set_defaults end |
#set_defaults ⇒ Object
36 37 38 39 40 |
# File 'lib/braai/matchers.rb', line 36 def set_defaults map(IterationMatcher, Braai::Handlers::Iteration) map(ConditionalMatcher, Braai::Handlers::Conditional) map(DefaultMatcher, Braai::Handlers::Default) end |
#unmap(regex) ⇒ Object
22 23 24 |
# File 'lib/braai/matchers.rb', line 22 def unmap(regex) self.matchers.delete(regex.to_s) end |