<commit_before>module SalesTax
  class Receipt
    def initialize(args = {})
      @items = args[:items] || []
    end

    def add_item(item)
      items << item
    end

    def print
      _print = ""
      total = BigDecimal('0')
      sales_taxes_total = BigDecimal('0')
      items.each do |item|
        total += item[:total_unit_price]
        sales_taxes_total += item[:unit_sales_tax]
        _print << print_item(item)
      end
      _print << "\n"
      _print << print_sales_taxes_total(sales_taxes_total)
      _print << print_total(total)
      _print
    end

    private

    attr_accessor :items

    def print_total(bd)
      total = format_bd_to_price_string(bd)
      "Total: #{total}\n"
    end

    def print_sales_taxes_total(bd)
      total  = format_bd_to_price_string(bd)
      "Sales Taxes: #{total}\n"
    end

    def print_item(item)
      taxed_price_str = format_bd_to_price_string(item[:total_unit_price])
      "#{item[:quantity]}, #{item[:description]}, #{taxed_price_str}\n"
    end

    def format_bd_to_price_string(bd)
      sprintf("%.2f", bd_to_float_str(bd))
    end

    def bd_to_float_str(bd)
      bd.to_s('F')
    end
  end
end
<commit_msg>Update Receipt class to deal with money strings.<commit_after>module SalesTax
  class Receipt
    def initialize(args = {})
      @items = args[:items] || []
    end

    def add_item(item)
      items << item
    end

    def print
      _print = ""
      total = BigDecimal('0')
      sales_taxes_total = BigDecimal('0')
      items.each do |item|
        total += BigDecimal(item[:total_unit_price])
        sales_taxes_total += BigDecimal(item[:unit_sales_tax])
        _print << print_item(item)
      end
      _print << "\n"
      _print << print_sales_taxes_total(sales_taxes_total)
      _print << print_total(total)
      _print
    end

    private

    attr_accessor :items

    def print_total(bd)
      total = format_to_money_string(bd.to_s('F'))
      "Total: #{total}\n"
    end

    def print_sales_taxes_total(bd)
      total  = format_to_money_string(bd.to_s('F'))
      "Sales Taxes: #{total}\n"
    end

    def print_item(item)
      taxed_price_str = format_to_money_string(item[:total_unit_price])
      "#{item[:quantity]}, #{item[:description]}, #{taxed_price_str}\n"
    end

    def format_to_money_string(str)
      sprintf("%.2f", str)
    end
  end
end

{'fraction_non_alphanumeric': 0.11625947767481044, 'fraction_numerical': 0.002527379949452401, 'mean_word_length': 2.6936236391912907, 'pattern_counts': {'":': 0, '<': 23, '<?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': '738393', 'n_tokens_mistral': 852, 'n_tokens_neox': 820, 'n_words': 155}