<commit_before>module Fourtyk
  def shorten_number
    
    if self.is_a?(String)
      self.gsub!(/[a-zA-z$,]/,"")
      num = self.to_i.round
      string = num.to_s
    else
      num = self.to_i
      string = num.to_s
    end
    
    case string.length
    when 4..6 
      label = "K"
      upper = 4
      lower = -3
    when 7..9 
      label = "M"
      upper = 7
      lower = -6
    when 10..12 
      label = "B"
      upper = 10
      lower = -9
    else
      label = nil
    end
    
    if label
      first = string[0..string.length - upper].to_i
      last = string[lower..lower+2].to_i * 0.001
      last = sprintf("%.1f", last).to_f
      num = first + last
      num = num.round if last.zero? || last == 1
    end
    
    "#{num}#{label}"
  end
  
  def shorten_money(options = {})
    options[:currency] ||= "$"
    "#{options[:currency]}#{self.shorten_number}"
  end
end

class Numeric
  include Fourtyk
end

class String
  include Fourtyk
end<commit_msg>fix up a few code duplications<commit_after>module Fourtyk
  def shorten_number
    if self.is_a?(String)
      self.gsub!(/[a-zA-z$,]/,"")
    end
    num = self.to_i
    string = num.to_s
    length = string.length
    
    case length
    when 4..6 
      label = "K"
      upper = 4
      lower = -3
    when 7..9 
      label = "M"
      upper = 7
      lower = -6
    when 10..12 
      label = "B"
      upper = 10
      lower = -9
    else
      label = nil
    end
    
    if label
      first = string[0..length - upper].to_i
      last = string[lower..lower+2].to_i * 0.001
      last = sprintf("%.1f", last).to_f
      num = first + last
      num = num.round if last.zero? || last == 1
    end
    
    "#{num}#{label}"
  end
  
  def shorten_money(options = {})
    options[:currency] ||= "$"
    "#{options[:currency]}#{self.shorten_number}"
  end
end

class Numeric # :nodoc:
  include Fourtyk
end

class String # :nodoc:
  include Fourtyk
end
{'fraction_non_alphanumeric': 0.13144329896907217, 'fraction_numerical': 0.023711340206185566, 'mean_word_length': 1.7376586741889986, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3460654', 'n_tokens_mistral': 733, 'n_tokens_neox': 706, 'n_words': 175}