Class: SRL::Regex::Multiplicity
- Inherits:
-
Object
- Object
- SRL::Regex::Multiplicity
- Defined in:
- lib/regex/multiplicity.rb
Overview
The multiplicity specifies by how much a given expression can be repeated.
Instance Attribute Summary collapse
-
#lower_bound ⇒ Object
readonly
The lowest acceptable repetition count.
-
#policy ⇒ Object
readonly
An indicator that specifies how to repeat (:greedy, :lazy, :possessive).
-
#upper_bound ⇒ Object
readonly
The highest possible repetition count.
Instance Method Summary collapse
-
#initialize(aLowerBound, anUpperBound, aPolicy) ⇒ Multiplicity
constructor
A new instance of Multiplicity.
-
#to_str ⇒ Object
Purpose: Return the String representation of the multiplicity.
Constructor Details
#initialize(aLowerBound, anUpperBound, aPolicy) ⇒ Multiplicity
Returns a new instance of Multiplicity.
19 20 21 22 23 |
# File 'lib/regex/multiplicity.rb', line 19 def initialize(aLowerBound, anUpperBound, aPolicy) @lower_bound = valid_lower_bound(aLowerBound) @upper_bound = valid_upper_bound(anUpperBound) @policy = valid_policy(aPolicy) end |
Instance Attribute Details
#lower_bound ⇒ Object (readonly)
The lowest acceptable repetition count
8 9 10 |
# File 'lib/regex/multiplicity.rb', line 8 def lower_bound @lower_bound end |
#policy ⇒ Object (readonly)
An indicator that specifies how to repeat (:greedy, :lazy, :possessive)
14 15 16 |
# File 'lib/regex/multiplicity.rb', line 14 def policy @policy end |
#upper_bound ⇒ Object (readonly)
The highest possible repetition count
11 12 13 |
# File 'lib/regex/multiplicity.rb', line 11 def upper_bound @upper_bound end |
Instance Method Details
#to_str ⇒ Object
Purpose: Return the String representation of the multiplicity.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/regex/multiplicity.rb', line 26 def to_str() case upper_bound when :more case lower_bound when 0 subresult = '*' when 1 subresult = '+' else subresult = "{#{lower_bound},}" end when lower_bound subresult = "{#{lower_bound}}" else if [lower_bound, upper_bound] == [0, 1] subresult = '?' else subresult = "{#{lower_bound},#{upper_bound}}" end end suffix = case policy when :greedy '' when :lazy '?' when :possessive '+' end return subresult + suffix end |