class Collapser
Constants
- DEFAULT_REPLACER
- REPLACED_CHARS
- VERSION
Attributes
replacer_arr[R]
replacer_arr_idx[RW]
text_arr[R]
Public Class Methods
new(text:, replacer: nil)
click to toggle source
# File lib/collapser.rb, line 19 def initialize(text:, replacer: nil) @text_arr = text.split('') @replacer_arr = (replacer || DEFAULT_REPLACER).split('') @replacer_arr_idx = 0 end
Public Instance Methods
run()
click to toggle source
# File lib/collapser.rb, line 27 def run text_arr.map { |char| convert_char(char: char) }.join end
Private Instance Methods
char_type(char:)
click to toggle source
# File lib/collapser.rb, line 52 def char_type(char:) return :other unless REPLACED_CHARS.include?(char) return :downcase if char.downcase == char :upcase end
convert_char(char:)
click to toggle source
# File lib/collapser.rb, line 35 def convert_char(char:) case char_type(char: char) when :other char when :downcase next_replace_char.downcase when :upcase next_replace_char.upcase end end
increment_replacer_arr_idx!()
click to toggle source
# File lib/collapser.rb, line 59 def increment_replacer_arr_idx! self.replacer_arr_idx = replacer_arr_idx + 1 self.replacer_arr_idx = 0 if replacer_arr_idx >= replacer_arr.size replacer_arr_idx end
next_replace_char()
click to toggle source
# File lib/collapser.rb, line 46 def next_replace_char char = replacer_arr[replacer_arr_idx] increment_replacer_arr_idx! char end