Class: Liquid::RangeLookup
- Inherits:
-
Object
- Object
- Liquid::RangeLookup
- Defined in:
- lib/liquid/range_lookup.rb
Defined Under Namespace
Classes: ParseTreeVisitor
Instance Attribute Summary collapse
-
#end_obj ⇒ Object
readonly
Returns the value of attribute end_obj.
-
#start_obj ⇒ Object
readonly
Returns the value of attribute start_obj.
Class Method Summary collapse
Instance Method Summary collapse
- #evaluate(context) ⇒ Object
-
#initialize(start_obj, end_obj) ⇒ RangeLookup
constructor
A new instance of RangeLookup.
Constructor Details
#initialize(start_obj, end_obj) ⇒ RangeLookup
Returns a new instance of RangeLookup.
17 18 19 20 |
# File 'lib/liquid/range_lookup.rb', line 17 def initialize(start_obj, end_obj) @start_obj = start_obj @end_obj = end_obj end |
Instance Attribute Details
#end_obj ⇒ Object (readonly)
Returns the value of attribute end_obj.
15 16 17 |
# File 'lib/liquid/range_lookup.rb', line 15 def end_obj @end_obj end |
#start_obj ⇒ Object (readonly)
Returns the value of attribute start_obj.
15 16 17 |
# File 'lib/liquid/range_lookup.rb', line 15 def start_obj @start_obj end |
Class Method Details
.parse(start_markup, end_markup) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/liquid/range_lookup.rb', line 5 def self.parse(start_markup, end_markup) start_obj = Expression.parse(start_markup) end_obj = Expression.parse(end_markup) if start_obj.respond_to?(:evaluate) || end_obj.respond_to?(:evaluate) new(start_obj, end_obj) else start_obj.to_i..end_obj.to_i end end |
Instance Method Details
#evaluate(context) ⇒ Object
22 23 24 25 26 |
# File 'lib/liquid/range_lookup.rb', line 22 def evaluate(context) start_int = to_integer(context.evaluate(@start_obj)) end_int = to_integer(context.evaluate(@end_obj)) start_int..end_int end |