Class: Kaiseki::RepeatParser

Inherits:
Object
  • Object
show all
Includes:
Parseable
Defined in:
lib/parser_repeat.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Parseable

#&, #action, #and?, #cast, #filter, #list, #merge, #not!, #one_or_more, #optional, #override, #parse, #predicate?, #protect, #repeat, #set, #skip, #tag_error, #tag_result, #to_parseable, #validate, #zero_or_more, #|

Constructor Details

#initialize(expected, min, max = nil) ⇒ RepeatParser

Returns a new instance of RepeatParser.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
# File 'lib/parser_repeat.rb', line 6

def initialize expected, min, max = nil
	raise ArgumentError, "expected must not be a predicate" if expected.predicate?
	@expected = expected.to_parseable
	@min = min
	@max = max
end

Instance Attribute Details

#expectedObject (readonly)

Returns the value of attribute expected.



4
5
6
# File 'lib/parser_repeat.rb', line 4

def expected
  @expected
end

#maxObject (readonly)

Returns the value of attribute max.



4
5
6
# File 'lib/parser_repeat.rb', line 4

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



4
5
6
# File 'lib/parser_repeat.rb', line 4

def min
  @min
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


13
14
15
# File 'lib/parser_repeat.rb', line 13

def eql? other
	other.is_a?(self.class) and other.expected == @expected and other.min == @min and other.max == @max
end

#to_sObject



19
20
21
22
23
24
25
# File 'lib/parser_repeat.rb', line 19

def to_s
	if @max
		@expected.to_s + " [#{@min}..#{@max}]"
	else
		@expected.to_s + " [#{@min}+]"
	end
end