<commit_before># encoding: utf-8

require "polish_number/version"

module PolishNumber
  HUNDREDS = ['', 'sto ', 'dwieście ', 'trzysta ', 'czterysta ', 'pięćset ', 'sześćset ',
    'siedemset ', 'osiemset ', 'dziewięćset ']

  TENS = ['', 'dziesięć ', 'dwadzieścia ', 'trzydzieści ', 'czterdzieści ', 'pięćdziesiąt ',
    'sześćdziesiąt ', 'siedemdziesiąt ', 'osiemdziesiąt ', 'dziewięćdziesiąt ']

  TEENS = ['', 'jedenaście ', 'dwanaście ', 'trzynaście ', 'czternaście ', 'piętnaście ',
    'szesnaście ', 'siedemnaście ', 'osiemnaście ', 'dziewiętnaście ']

  UNITIES = ['', 'jeden ', 'dwa ', 'trzy ', 'cztery ', 'pięć ', 'sześć ', 'siedem ', 'osiem ',
    'dziewięć ']

  ZERO = 'zero'

  THOUSANDS = {:one => 'tysiąc', :few => 'tysiące', :many => 'tysięcy'}

  MILLIONS = {:one => 'milion', :few => 'miliony', :many => 'milionów'}

  CENTS = [:auto, :no, :words, :digits]

  CURRENCIES = {
    :NO => {:one => '', :few => '', :many => '',
            :one_100 => 'setna', :few_100 => 'setne', :many_100 => 'setnych', :gender_100 => :she},
    :PLN => {:one => 'złoty', :few => 'złote', :many => 'złotych',
            :one_100 => 'grosz', :few_100 => 'grosze', :many_100 => 'groszy'},
    :USD => { :one => 'dolar', :few => 'dolary', :many => 'dolarów',
            :one_100 => 'cent', :few_100 => 'centy', :many_100 => 'centów'},
    :EUR => { :one => 'euro', :few => 'euro', :many => 'euro', :gender => :it,
            :one_100 => 'cent', :few_100 => 'centy', :many_100 => 'centów'},
    :GBP => { :one => 'funt', :few => 'funty', :many => 'funtów',
            :one_100 => 'pens', :few_100 => 'pensy', :many_100 => 'pensów'},
    :CHF => { :one => 'frank', :few => 'franki', :many => 'franków',
            :one_100 => 'centym', :few_100 => 'centymy', :many_100 => 'centymów'},
    :SEK => { :one => 'korona', :few => 'korony', :many => 'koron', :gender => :she,
            :one_100 => 'öre', :few_100 => 'öre', :many_100 => 'öre', :gender_100 => :it}
  }

  def self.validate_and_options(number, options)
    if options[:currency] && !CURRENCIES.has_key?(options[:currency])
      raise ArgumentError, "Unknown :currency option '#{options[:currency].inspect}'." +
                  " Choose one from: #{CURRENCIES.inspect}"
    end

    if options[:cents] && !CENTS.include?(options[:cents])
      raise ArgumentError, "Unknown :cents option '#{options[:cents].inspect}'." +
                  " Choose one from: #{CENTS.inspect}"
    end

    options[:cents] ||= :auto

    unless (0..999999999).include? number
      raise ArgumentError, 'number should be in 0..999999999 range'
    end
    options
  end

  def self.translate(number, options={})

    options = validate_and_options(number, options)

    number = number.to_i if options[:cents]==:no
    formatted_number = sprintf('%012.2f', number)
    currency = CURRENCIES[options[:currency] || :NO]

    if number == 0
      result = ZERO.dup
    else
      digits = formatted_number.chars.map { |char| char.to_i }
      digits_i = digits[0..8]
      result = process_1_999999999(digits, number, currency)
    end

    if options[:currency] && !result.empty?
      result << ' '
      result << currency[classify(number.to_i, digits_i)]
    end
    process_99_0(result, digits, options, formatted_number, currency)
  end

  def self.add_currency(name, hash)
    CURRENCIES[name]=hash
  end

  private

  def self.process_99_0(result, digits, options, formatted_number, currency)
    if options[:cents] == :words ||
        (options[:cents] == :auto && formatted_number[-2..-1] != '00')
      digits_cents = digits[-3..-1] if digits
      number_cents = formatted_number[-2..-1].to_i
      result << ' i ' unless result.empty?
      result << process_0_999(digits_cents, number_cents, currency[:gender_100] || :hi) if digits
      result << ZERO.dup if formatted_number[-2..-1] == '00'
      result.strip!
      result << ' '
      result << currency[classify(formatted_number[-2..-1].to_i, digits_cents, true)]
    elsif options[:cents] == :digits
      result << ' '
      result << formatted_number[-2..-1]
      result << '/100'
    end

    result
  end

  def self.process_1_999999999(digits, number, currency)
    result = ''
    result << process_0_999(digits[0..2], number, :number)
    result << millions(number.to_i/1000000, digits[0..2])
    result.strip!<commit_msg>More code_climate.<commit_after># encoding: utf-8

require "polish_number/version"

module PolishNumber
  HUNDREDS = ['', 'sto ', 'dwieście ', 'trzysta ', 'czterysta ', 'pięćset ', 'sześćset ',
    'siedemset ', 'osiemset ', 'dziewięćset ']

  TENS = ['', 'dziesięć ', 'dwadzieścia ', 'trzydzieści ', 'czterdzieści ', 'pięćdziesiąt ',
    'sześćdziesiąt ', 'siedemdziesiąt ', 'osiemdziesiąt ', 'dziewięćdziesiąt ']

  TEENS = ['', 'jedenaście ', 'dwanaście ', 'trzynaście ', 'czternaście ', 'piętnaście ',
    'szesnaście ', 'siedemnaście ', 'osiemnaście ', 'dziewiętnaście ']

  UNITIES = ['', 'jeden ', 'dwa ', 'trzy ', 'cztery ', 'pięć ', 'sześć ', 'siedem ', 'osiem ',
    'dziewięć ']

  ZERO = 'zero'

  THOUSANDS = {:one => 'tysiąc', :few => 'tysiące', :many => 'tysięcy'}

  MILLIONS = {:one => 'milion', :few => 'miliony', :many => 'milionów'}

  CENTS = [:auto, :no, :words, :digits]

  CURRENCIES = {
    :NO => {:one => '', :few => '', :many => '',
            :one_100 => 'setna', :few_100 => 'setne', :many_100 => 'setnych', :gender_100 => :she},
    :PLN => {:one => 'złoty', :few => 'złote', :many => 'złotych',
            :one_100 => 'grosz', :few_100 => 'grosze', :many_100 => 'groszy'},
    :USD => { :one => 'dolar', :few => 'dolary', :many => 'dolarów',
            :one_100 => 'cent', :few_100 => 'centy', :many_100 => 'centów'},
    :EUR => { :one => 'euro', :few => 'euro', :many => 'euro', :gender => :it,
            :one_100 => 'cent', :few_100 => 'centy', :many_100 => 'centów'},
    :GBP => { :one => 'funt', :few => 'funty', :many => 'funtów',
            :one_100 => 'pens', :few_100 => 'pensy', :many_100 => 'pensów'},
    :CHF => { :one => 'frank', :few => 'franki', :many => 'franków',
            :one_100 => 'centym', :few_100 => 'centymy', :many_100 => 'centymów'},
    :SEK => { :one => 'korona', :few => 'korony', :many => 'koron', :gender => :she,
            :one_100 => 'öre', :few_100 => 'öre', :many_100 => 'öre', :gender_100 => :it}
  }

  def self.validate_and_options(number, options)
    if options[:currency] && !CURRENCIES.has_key?(options[:currency])
      raise ArgumentError, "Unknown :currency option '#{options[:currency].inspect}'." +
                  " Choose one from: #{CURRENCIES.inspect}"
    end

    if options[:cents] && !CENTS.include?(options[:cents])
      raise ArgumentError, "Unknown :cents option '#{options[:cents].inspect}'." +
                  " Choose one from: #{CENTS.inspect}"
    end

    options[:cents] ||= :auto

    unless (0..999999999).include? number
      raise ArgumentError, 'number should be in 0..999999999 range'
    end
    options
  end

  def self.translate(number, options={})

    options = validate_and_options(number, options)

    number = number.to_i if options[:cents]==:no
    formatted_number = sprintf('%012.2f', number)
    currency = CURRENCIES[options[:currency] || :NO]

    if number == 0
      result = ZERO.dup
    else
      digits = formatted_number.chars.map { |char| char.to_i }
      digits_i = digits[0..8]
      result = process_1_999999999(digits, number, currency)
    end

    if options[:currency] && !result.empty?
      result << ' ' + currency[classify(number.to_i, digits_i)]
    end

    process_99_0(result, digits, options, formatted_number[-2..-1], currency)

  end

  def self.add_currency(name, hash)
    CURRENCIES[name]=hash
  end

  private

  def self.process_99_0(result, digits, options, formatted_sub_number, currency)
    if options[:cents] == :words ||
        (options[:cents] == :auto && formatted_sub_number != '00')
      digits_cents = digits[-3..-1] if digits
      number_cents = formatted_sub_number.to_i
      result << ' i ' unless result.empty?
      result << process_0_999(digits_cents, number_cents, currency[:gender_100] || :hi) if digits
      result << ZERO.dup if formatted_sub_number == '00'
      result.strip!
      result << ' '
      result << currency[classify(formatted_sub_number.to_i, digits_cents, true)]
    elsif options[:cents] == :digits
      result << ' '
      result << formatted_sub_number
      result << '/100'
    end

    result
  end

  def self.process_1_999999999(digits, number, currency)
    result = ''
    result << process_0_999(digits[0..2], number, :number)
    result << millions(number.to_i/1000000, digits[0..2])
    result.strip!
{'fraction_non_alphanumeric': 0.1907067911910527, 'fraction_numerical': 0.03689611437795457, 'mean_word_length': 3.247796278158668, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 121, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 8, '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': '1417101', 'n_tokens_mistral': 3507, 'n_tokens_neox': 3182, 'n_words': 659}