Class: TwitterCldr::Parsers::UnicodeRegexParser::CharacterRange
- Inherits:
-
Component
- Object
- Component
- TwitterCldr::Parsers::UnicodeRegexParser::CharacterRange
- Defined in:
- lib/twitter_cldr/parsers/unicode_regex/character_range.rb
Overview
Regex character range eg. a-z or 0-9 Can only exist in character classes
Instance Attribute Summary collapse
-
#final ⇒ Object
readonly
Returns the value of attribute final.
-
#initial ⇒ Object
readonly
Returns the value of attribute initial.
Instance Method Summary collapse
- #codepoints ⇒ Object
-
#initialize(initial, final) ⇒ CharacterRange
constructor
A new instance of CharacterRange.
- #to_regexp_str ⇒ Object
- #to_s ⇒ Object
- #to_set ⇒ Object
-
#type ⇒ Object
Unfortunately, due to the ambiguity of having both character ranges and set operations in the same syntax (which both use the “-” operator and square brackets), we have to treat CharacterRange as both a token and an operand.
Constructor Details
#initialize(initial, final) ⇒ CharacterRange
Returns a new instance of CharacterRange.
16 17 18 19 |
# File 'lib/twitter_cldr/parsers/unicode_regex/character_range.rb', line 16 def initialize(initial, final) @initial = initial @final = final end |
Instance Attribute Details
#final ⇒ Object (readonly)
Returns the value of attribute final.
14 15 16 |
# File 'lib/twitter_cldr/parsers/unicode_regex/character_range.rb', line 14 def final @final end |
#initial ⇒ Object (readonly)
Returns the value of attribute initial.
14 15 16 |
# File 'lib/twitter_cldr/parsers/unicode_regex/character_range.rb', line 14 def initial @initial end |
Instance Method Details
#codepoints ⇒ Object
36 37 38 |
# File 'lib/twitter_cldr/parsers/unicode_regex/character_range.rb', line 36 def codepoints to_set.to_full_a end |
#to_regexp_str ⇒ Object
40 41 42 |
# File 'lib/twitter_cldr/parsers/unicode_regex/character_range.rb', line 40 def to_regexp_str set_to_regex(to_set) end |
#to_s ⇒ Object
44 45 46 |
# File 'lib/twitter_cldr/parsers/unicode_regex/character_range.rb', line 44 def to_s "#{initial.to_s}-#{final.to_s}" end |
#to_set ⇒ Object
30 31 32 33 34 |
# File 'lib/twitter_cldr/parsers/unicode_regex/character_range.rb', line 30 def to_set TwitterCldr::Utils::RangeSet.new( [initial.to_set.to_full_a.first..final.to_set.to_full_a.first] ) end |
#type ⇒ Object
Unfortunately, due to the ambiguity of having both character ranges and set operations in the same syntax (which both use the “-” operator and square brackets), we have to treat CharacterRange as both a token and an operand. This type method helps it behave like a token.
26 27 28 |
# File 'lib/twitter_cldr/parsers/unicode_regex/character_range.rb', line 26 def type :character_range end |