Class: TurkishRanges::TrText
- Inherits:
-
Object
- Object
- TurkishRanges::TrText
- Includes:
- Comparable
- Defined in:
- lib/turkish_ranges/tr_text.rb
Overview
Represents a character sequence in Turkish language
Constant Summary collapse
- MAP =
Using for character mapping
'DHJPTVdhiptvÈğıØşÝèĠIJøŠý'.chars.zip('ÇĞİÖŞÜçğıöşüDHJPTVdhiptv'.chars).to_h.freeze
- ASCII_ALPHABET =
Using for calculating character codes
'ABCÇDEFGĞHIİJKLMNOÖPQRSŞTUÜVWXYZabcçdefgğhıijklmnoöpqrsştuüvwxyz' .chars.map.with_index { [_1, _2 + 65] }.to_h.freeze
Instance Attribute Summary collapse
-
#letters ⇒ String
readonly
Sets the letters for the ‘TrText`.
-
#letters_length ⇒ String
readonly
Sets the letters for the ‘TrText`.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer
Using for object comparison.
-
#code ⇒ Integer
Calculates codepoint of a single characacter based on ASCII_ALPHABET.
-
#initialize(letters) ⇒ TrText
constructor
A new instance of TrText.
-
#inspect ⇒ String
Overloading Object#inspect.
-
#succ ⇒ TrText
Next successor character sequence.
-
#succ_letter ⇒ String
Calculates the successor string from ‘letters`.
-
#to_s ⇒ String
Overloading Object#to_s.
Constructor Details
#initialize(letters) ⇒ TrText
A new instance of TrText
23 24 25 26 |
# File 'lib/turkish_ranges/tr_text.rb', line 23 def initialize(letters) @letters = letters @letters_length = letters.length end |
Instance Attribute Details
#letters ⇒ String (readonly)
Sets the letters for the ‘TrText`.
10 11 12 |
# File 'lib/turkish_ranges/tr_text.rb', line 10 def letters @letters end |
#letters_length ⇒ String (readonly)
Sets the letters for the ‘TrText`.
10 11 12 |
# File 'lib/turkish_ranges/tr_text.rb', line 10 def letters_length @letters_length end |
Instance Method Details
#<=>(other) ⇒ Integer
Using for object comparison
32 33 34 35 36 |
# File 'lib/turkish_ranges/tr_text.rb', line 32 def <=>(other) return 0 if letters == other.letters compare_chars(zip_chars_with(other)) end |
#code ⇒ Integer
Calculates codepoint of a single characacter based on ASCII_ALPHABET
41 42 43 |
# File 'lib/turkish_ranges/tr_text.rb', line 41 def code ASCII_ALPHABET[letters] || letters&.ord.to_i end |
#inspect ⇒ String
Overloading Object#inspect
72 73 74 |
# File 'lib/turkish_ranges/tr_text.rb', line 72 def inspect letters end |
#succ ⇒ TrText
Next successor character sequence
58 59 60 |
# File 'lib/turkish_ranges/tr_text.rb', line 58 def succ TrText.new(succ_letter) end |
#succ_letter ⇒ String
Calculates the successor string from ‘letters`
48 49 50 51 52 53 |
# File 'lib/turkish_ranges/tr_text.rb', line 48 def succ_letter successor = letters.succ change = successor.delete(letters) successor.sub!(change, MAP[change]) if change.length == 1 && MAP.key?(change) successor end |
#to_s ⇒ String
Overloading Object#to_s
65 66 67 |
# File 'lib/turkish_ranges/tr_text.rb', line 65 def to_s letters end |