Class: Liquidscript::Scanner::Base::Context
- Inherits:
-
Object
- Object
- Liquidscript::Scanner::Base::Context
- Defined in:
- lib/liquidscript/scanner/base/context.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #exit ⇒ Object
- #find_matcher(with) ⇒ Object
- #get(key) ⇒ Object
- #init ⇒ Object
-
#initialize(name) ⇒ Context
constructor
A new instance of Context.
- #on(matcher) ⇒ Object
- #set(key, matcher) ⇒ Object
Constructor Details
#initialize(name) ⇒ Context
Returns a new instance of Context.
8 9 10 11 12 |
# File 'lib/liquidscript/scanner/base/context.rb', line 8 def initialize(name) @name = name @matches = {} @temps = {} end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/liquidscript/scanner/base/context.rb', line 6 def name @name end |
Instance Method Details
#exit ⇒ Object
25 26 27 |
# File 'lib/liquidscript/scanner/base/context.rb', line 25 def exit EXIT end |
#find_matcher(with) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/liquidscript/scanner/base/context.rb', line 14 def find_matcher(with) best_match = [0, nil, nil] @matches.each do |k, v| if with.match?(k) && with.matched_size > best_match[0] best_match = [with.matched_size, k, v] end end best_match[1..-1] end |
#get(key) ⇒ Object
41 42 43 |
# File 'lib/liquidscript/scanner/base/context.rb', line 41 def get(key) normalize_matcher @temps[key] end |
#init ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/liquidscript/scanner/base/context.rb', line 29 def init if block_given? @init = Proc.new else @init || proc {} end end |
#on(matcher) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/liquidscript/scanner/base/context.rb', line 45 def on(matcher) key = nil value = nil if block_given? key = normalize_matcher matcher value = Proc.new else key = normalize_matcher matcher.keys.first value = matcher.values.first end @matches[key] = value end |
#set(key, matcher) ⇒ Object
37 38 39 |
# File 'lib/liquidscript/scanner/base/context.rb', line 37 def set(key, matcher) @temps[key] = matcher end |