class MARC::Spec::Parsing::ClosedIntRange
Constants
- INT_RANGE_RE
- SIMPLE_CLASS_NAME
Public Instance Methods
to_s_inner(_prec)
click to toggle source
# File lib/marc/spec/parsing/closed_int_range.rb, line 22 def to_s_inner(_prec) SIMPLE_CLASS_NAME end
try(source, context, _consume_all)
click to toggle source
# File lib/marc/spec/parsing/closed_int_range.rb, line 11 def try(source, context, _consume_all) source_str = source.instance_variable_get(:@str) # TODO: something less hacky return context.err(self, source, 'Not a non-negative integer range') unless (range_str = source_str.check(INT_RANGE_RE)) s, e = range_str.match(INT_RANGE_RE)[1, 2] return context.err(self, source, "#{s} !<= #{e}") unless s.to_i <= e.to_i sv, _, ev = [s.size, 1, e.size].map { |l| source.consume(l) } # discard hyphen succ(from: sv, to: ev) end