Class: Lexr::Dsl
- Inherits:
-
Object
- Object
- Lexr::Dsl
- Defined in:
- lib/lexr.rb
Instance Method Summary collapse
- #ignores(rule_hash) ⇒ Object
-
#initialize ⇒ Dsl
constructor
A new instance of Dsl.
- #matches(rule_hash) ⇒ Object
- #new(str) ⇒ Object
Constructor Details
#initialize ⇒ Dsl
Returns a new instance of Dsl.
97 98 99 |
# File 'lib/lexr.rb', line 97 def initialize @rules = [] end |
Instance Method Details
#ignores(rule_hash) ⇒ Object
108 109 110 |
# File 'lib/lexr.rb', line 108 def ignores(rule_hash) matches rule_hash.merge(:ignore => true) end |
#matches(rule_hash) ⇒ Object
101 102 103 104 105 106 |
# File 'lib/lexr.rb', line 101 def matches(rule_hash) pattern = rule_hash.keys.reject { |k| k.class == Symbol }.first symbol = rule_hash[pattern] opts = rule_hash.delete_if { |k, v| k.class != Symbol } @rules << Rule.new(pattern, symbol, opts) end |
#new(str) ⇒ Object
112 113 114 |
# File 'lib/lexr.rb', line 112 def new(str) Lexr.new(str, @rules) end |