class Quby::Compiler::Services::QubyProxy::ShortenKeysUniq
Public Class Methods
new()
click to toggle source
# File lib/quby/compiler/services/quby_proxy.rb, line 334 def initialize @seen_results = [] end
Public Instance Methods
shorten_one(key)
click to toggle source
# File lib/quby/compiler/services/quby_proxy.rb, line 338 def shorten_one(key) key = key.to_s limit = 2 shortened_key = nil loop do shortened_key = key[0..limit] if key[limit] == "_" limit += 1 next end break unless @seen_results.include?(shortened_key) raise "duplicate key, #{key}" if shortened_key.length == key.length limit += 1 end @seen_results << shortened_key shortened_key end
shorten_two(first_key, second_key)
click to toggle source
# File lib/quby/compiler/services/quby_proxy.rb, line 357 def shorten_two(first_key, second_key) first_key = first_key.to_s second_key = second_key.to_s first_limit = [2, first_key.length - 1].min second_limit = 0 shortened_key = nil loop do shortened_key = "#{first_key[0..first_limit]}_#{second_key[0..second_limit]}" if first_key[first_limit] == "_" first_limit += 1 next end if second_key[second_limit] == "_" second_limit += 1 next end break unless @seen_results.include?(shortened_key) raise "duplicate key, #{first_key}_#{second_key}" if first_limit == (first_key.length - 1) && second_limit == (second_key.length - 1) if second_limit == (second_key.length - 1) first_limit += 1 second_limit = 0 else second_limit += 1 end end @seen_results << shortened_key shortened_key end