Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/twitter-text/extractor.rb
Instance Method Summary collapse
-
#char_length ⇒ Object
Helper function to count the character length by first converting to an array.
-
#to_char_a ⇒ Object
Helper function to convert this string into an array of unicode characters.
Instance Method Details
#char_length ⇒ Object
Helper function to count the character length by first converting to an array. This is needed because with unicode strings, the return value of length may be incorrect
7 8 9 10 11 12 13 |
# File 'lib/twitter-text/extractor.rb', line 7 def char_length if respond_to? :codepoints length else chars.kind_of?(Enumerable) ? chars.to_a.size : chars.size end end |
#to_char_a ⇒ Object
Helper function to convert this string into an array of unicode characters.
16 17 18 19 20 21 22 23 24 |
# File 'lib/twitter-text/extractor.rb', line 16 def to_char_a @to_char_a ||= if chars.kind_of?(Enumerable) chars.to_a else char_array = [] 0.upto(char_length - 1) { |i| char_array << [chars.slice(i)].pack('U') } char_array end end |