<commit_before>class VatService
  ViesDown = Class.new(StandardError)
  VatCharge = Struct.new(:amount, :rate)

  # http://ec.europa.eu/taxation_customs/resources/documents/taxation/vat/how_vat_works/rates/vat_rates_en.pdf
  VAT_RATES = {
    'BE' => 21,
    'BG' => 20,
    'CZ' => 21,
    'DK' => 25,
    'DE' => 19,
    'EE' => 20,
    'EL' => 23,
    'ES' => 21,
    'FR' => 20,
    'HR' => 25,
    'IE' => 23,
    'IT' => 22,
    'CY' => 19,
    'LV' => 21,
    'LT' => 21,
    'LU' => 17,
    'HU' => 27,
    'MT' => 18,
    'NL' => 21,
    'AT' => 20,
    'PL' => 23,
    'PT' => 23,
    'RO' => 24,
    'SI' => 22,
    'SK' => 20,
    'FI' => 24,
    'SE' => 25,
    'GB' => 20  # Country code of the United Kingdom
  }

  # Calculates VAT amount based on country and whether the customer
  # is a company or not.
  #
  # amount           - Base amount that is VAT taxable in cents (or not).
  # country_code     - ISO country code.
  # vat_registered   - true if a customer is vat registered
  #
  # Returns amount of VAT payable, in cents (rounded down).
  def calculate(amount:, country_code:, vat_registered:)
    rate = vat_rate(country_code: country_code,
      vat_registered: vat_registered)
    VatCharge.new((amount*rate/100.0).round, rate)
  end

  # Checks if given VAT number is valid.
  #
  # vat_number  - VAT number to be validated
  #
  # Returns true or false
  def valid?(vat_number:)
    vies_valid = Valvat::Lookup.validate(vat_number)
    if vies_valid.nil?
      Valvat.new(vat_number).valid_checksum?
    else
      vies_valid
    end
  end<commit_msg>annotate country codes<commit_after>class VatService
  ViesDown = Class.new(StandardError)
  VatCharge = Struct.new(:amount, :rate)

  # http://ec.europa.eu/taxation_customs/resources/documents/taxation/vat/how_vat_works/rates/vat_rates_en.pdf
  VAT_RATES = {
    'BE' => 21, # Belgium
    'BG' => 20, # Bulgaria
    'CZ' => 21, # Czech Republic
    'DK' => 25, # Denmark
    'DE' => 19, # Germany
    'EE' => 20, # Estonia
    'EL' => 23, # Greece
    'ES' => 21, # Spain
    'FR' => 20, # France
    'HR' => 25, # Croatia
    'IE' => 23, # Ireland
    'IT' => 22, # Italy
    'CY' => 19, # Cryprus
    'LV' => 21, # Latvia
    'LT' => 21, # Lithuania
    'LU' => 17, # Luxembourg
    'HU' => 27, # Hungary
    'MT' => 18, # Malta
    'NL' => 21, # Netherlands
    'AT' => 20, # Austria
    'PL' => 23, # Poland
    'PT' => 23, # Portugal
    'RO' => 24, # Romania
    'SI' => 22, # Slovenia
    'SK' => 20, # Slovakia
    'FI' => 24, # Finland
    'SE' => 25, # Sweden
    'GB' => 20  # United Kingdom
  }

  # Calculates VAT amount based on country and whether the customer
  # is a company or not.
  #
  # amount           - Base amount that is VAT taxable in cents (or not).
  # country_code     - ISO country code.
  # vat_registered   - true if a customer is vat registered
  #
  # Returns amount of VAT payable, in cents (rounded down).
  def calculate(amount:, country_code:, vat_registered:)
    rate = vat_rate(country_code: country_code,
      vat_registered: vat_registered)
    VatCharge.new((amount*rate/100.0).round, rate)
  end

  # Checks if given VAT number is valid.
  #
  # vat_number  - VAT number to be validated
  #
  # Returns true or false
  def valid?(vat_number:)
    vies_valid = Valvat::Lookup.validate(vat_number)
    if vies_valid.nil?
      Valvat.new(vat_number).valid_checksum?
    else
      vies_valid
    end
  end
{'fraction_non_alphanumeric': 0.1469732246798603, 'fraction_numerical': 0.034924330616996506, 'mean_word_length': 2.514314928425358, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 59, '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': '1633071', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1257, 'n_words': 341}