class Regex::CharRange

A binary expression that represents a contiguous range of characters. Assumption: characters are ordered by codepoint

Public Class Methods

new(theLowerBound, theUpperBound) click to toggle source

Constructor.

thelowerBound

A character that will be the lower bound value for the range.

theUpperBound

A character that will be the upper bound value for the range.

TODO: optimisation. Build a Character if lower bound == upper bound.

Calls superclass method
# File lib/regex/char_range.rb, line 17
def initialize(theLowerBound, theUpperBound)
  range = validated_range(theLowerBound, theUpperBound)
  super(range)
end

Public Instance Methods

lower() click to toggle source

Return the lower bound of the range.

# File lib/regex/char_range.rb, line 23
def lower
  children.first
end
upper() click to toggle source

Return the upper bound of the range.

# File lib/regex/char_range.rb, line 28
def upper
  children.last
end

Protected Instance Methods

text_repr() click to toggle source

Conversion method re-definition. Purpose: Return the String representation of the concatented expressions.

# File lib/regex/char_range.rb, line 36
def text_repr
  "#{lower.to_str}-#{upper.to_str}"
end

Private Instance Methods

validated_range(theLowerBound, theUpperBound) click to toggle source

Validation method. Returns a couple of Characters.after their validation.

# File lib/regex/char_range.rb, line 43
def validated_range(theLowerBound, theUpperBound)
  msg = 'Character range error: lower bound is greater than upper bound.'
  raise StandardError, msg if theLowerBound.codepoint > theUpperBound.codepoint

  return [theLowerBound, theUpperBound]
end