Sha256: fc77f4c1f98013a29d088cd3442f6c0b5e43a296eb029de6b674b92d84f176ea

Contents?: true

Size: 831 Bytes

Versions: 11

Compression:

Stored size: 831 Bytes

Contents

module Liquid
  class RangeLookup
    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

    def initialize(start_obj, end_obj)
      @start_obj = start_obj
      @end_obj = end_obj
    end

    def evaluate(context)
      start_int = to_integer(context.evaluate(@start_obj))
      end_int = to_integer(context.evaluate(@end_obj))
      start_int..end_int
    end

    private

    def to_integer(input)
      case input
      when Integer
        input
      when NilClass, String
        input.to_i
      else
        Utils.to_integer(input)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
liquid-4.0.4 lib/liquid/range_lookup.rb
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/liquid-4.0.3/lib/liquid/range_lookup.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/liquid-4.0.3/lib/liquid/range_lookup.rb
liquid-4.0.3 lib/liquid/range_lookup.rb
liquid-4.0.2 lib/liquid/range_lookup.rb
liquid-4-0-2-4.0.2 lib/liquid/range_lookup.rb
liquid-4.0.1 lib/liquid/range_lookup.rb
liquid-4.0.0 lib/liquid/range_lookup.rb
liquid-4.0.0.rc3 lib/liquid/range_lookup.rb
liquid-4.0.0.rc2 lib/liquid/range_lookup.rb
liquid-4.0.0.rc1 lib/liquid/range_lookup.rb