Class: TwitterCldr::Parsers::UnicodeRegexParser::Literal
- Defined in:
- lib/twitter_cldr/parsers/unicode_regex/literal.rb
Constant Summary collapse
- SPECIAL_CHARACTERS =
{ "s" => [32], # space "t" => [9], # tab "r" => [13], # carriage return "n" => [10], # newline "f" => [12], # form feed "d" => ("0".."9").to_a.map { |c| ordinalize(c) }, "w" => (("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a + ["_"]).map { |c| ordinalize(c) } }
Instance Attribute Summary collapse
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
-
.ordinalize(char) ⇒ Object
ord is good enough (don’t need unpack) because ASCII chars have the same numbers as their unicode equivalents.
Instance Method Summary collapse
-
#initialize(text) ⇒ Literal
constructor
A new instance of Literal.
- #to_regexp_str ⇒ Object
- #to_s ⇒ Object
- #to_set ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(text) ⇒ Literal
Returns a new instance of Literal.
33 34 35 |
# File 'lib/twitter_cldr/parsers/unicode_regex/literal.rb', line 33 def initialize(text) @text = text end |
Instance Attribute Details
#text ⇒ Object (readonly)
Returns the value of attribute text.
11 12 13 |
# File 'lib/twitter_cldr/parsers/unicode_regex/literal.rb', line 11 def text @text end |
Class Method Details
.ordinalize(char) ⇒ Object
ord is good enough (don’t need unpack) because ASCII chars have the same numbers as their unicode equivalents
15 16 17 18 19 20 21 |
# File 'lib/twitter_cldr/parsers/unicode_regex/literal.rb', line 15 def self.ordinalize(char) if char.respond_to?(:ord) char.ord else char[0] end end |
Instance Method Details
#to_regexp_str ⇒ Object
37 38 39 |
# File 'lib/twitter_cldr/parsers/unicode_regex/literal.rb', line 37 def to_regexp_str text end |
#to_s ⇒ Object
59 60 61 |
# File 'lib/twitter_cldr/parsers/unicode_regex/literal.rb', line 59 def to_s text end |
#to_set ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/twitter_cldr/parsers/unicode_regex/literal.rb', line 41 def to_set if text =~ /^\\/ special_char = text[1..-1] if SPECIAL_CHARACTERS.include?(special_char.downcase) set_for_special_char(special_char) else TwitterCldr::Utils::RangeSet.from_array([ self.class.ordinalize(special_char) ]) end else TwitterCldr::Utils::RangeSet.from_array([ self.class.ordinalize(text) ]) end end |
#type ⇒ Object
63 64 65 |
# File 'lib/twitter_cldr/parsers/unicode_regex/literal.rb', line 63 def type :literal end |