Class: BetaCode
- Inherits:
-
Object
- Object
- BetaCode
- Defined in:
- lib/beta_code.rb
Class Method Summary collapse
-
.beta_code_to_greek(beta_code, custom_map: {}) ⇒ Object
This method is absurd.
- .greek_to_beta_code(greek, custom_map: {}) ⇒ Object
Class Method Details
.beta_code_to_greek(beta_code, custom_map: {}) ⇒ Object
This method is absurd. But having the logic all in one method makes it easier to work with than having it spread across multiple methods. It also makes it easier to compare the logic to the Beta Code libraries in other languages. rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/beta_code.rb', line 15 def self.beta_code_to_greek(beta_code, custom_map: {}) map = beta_code_to_unicode_map.merge(stringify_keys(custom_map)) beta_code_characters = beta_code.chars greek_characters = [] start = 0 max_beta_code_character_length = map.keys.map(&:length).max while start <= beta_code_characters.length current_character = beta_code_characters[start] new_start = start + 1 max_length = [beta_code_characters.length, start + max_beta_code_character_length].min last = new_start while last <= max_length slice = beta_code_characters[start...last].join('') if map[slice] current_character = map[slice] new_start = last end last += 1 end greek_characters << current_character start = new_start end sigma_to_end_of_word_sigma(greek_characters.join('')) end |
.greek_to_beta_code(greek, custom_map: {}) ⇒ Object
4 5 6 7 8 |
# File 'lib/beta_code.rb', line 4 def self.greek_to_beta_code(greek, custom_map: {}) map = unicode_to_beta_code_map.merge(stringify_keys(custom_map)) greek.unicode_normalize.chars.map { |c| map[c] || c }.join('') end |