<commit_before># Think-about-it: use a factory pattern to differentiate expense and income
#                 http://katafrakt.me/2015/05/15/when-you-call-object-new/
require 'lib/common/occurance'

module Model
  module Budget
    class Item
      ITEM_ERROR_MESSAGE = 'This is not a budget item'
      private_constant :ITEM_ERROR_MESSAGE

      attr_accessor :description, :category, :amount
      attr_reader :id

      # TODO: use merge for defaults
      def initialize(params = {})
        u_occurance = params.fetch(:occurance, :monthly)
        @occurance = Common::Occurance.new u_occurance
        @id = params.fetch(:id)
        @description = params.fetch(:description, 'no description')
        @category = params.fetch(:category, 'misc')
        @amount = params.fetch(:amount, 0.00).to_f.round(2) # FIXME: figure out how to use bankers rounding
      end

      def occurance
        @occurance.to_s
      end

      def occurance=(new_occurance)
        occurance = Common::Occurance.new new_occurance
        @amount = @occurance.generate_price_conversion(occurance).call(@amount)
        @occurance = occurance
      end

      def as_credit!
        @amount = -@amount
      end

      def as_debit!
        @amount = @amount.abs
      end

      def to_s
        "#{@description} (Category: #{@category}) #{@amount}, #{@occurance}"
      end

      def debit?
        @amount > 0
      end

      def credit?
        @amount < 0
      end

      def amount_for(occurance_type)
        target = Common::Occurance.new occurance_type
        proc_price = @occurance.generate_price_conversion target
        proc_price.call(@amount)
      end

      def ==(other)
        fail ArgumentError, ITEM_ERROR_MESSAGE unless other.instance_of?(Budget::Item)
        @description == other.description && @amount == other.amount &&
          @id == other.id && @category == other.category
      end
    end
  end
end
<commit_msg>change level of TODO<commit_after># Think-about-it: use a factory pattern to differentiate expense and income
#                 http://katafrakt.me/2015/05/15/when-you-call-object-new/
require 'lib/common/occurance'

module Model
  module Budget
    class Item
      ITEM_ERROR_MESSAGE = 'This is not a budget item'
      private_constant :ITEM_ERROR_MESSAGE

      attr_accessor :description, :category, :amount
      attr_reader :id

      # FIXME: use merge for defaults
      def initialize(params = {})
        u_occurance = params.fetch(:occurance, :monthly)
        @occurance = Common::Occurance.new u_occurance
        @id = params.fetch(:id)
        @description = params.fetch(:description, 'no description')
        @category = params.fetch(:category, 'misc')
        @amount = params.fetch(:amount, 0.00).to_f.round(2) # TODO: figure out how to use bankers rounding
      end

      def occurance
        @occurance.to_s
      end

      def occurance=(new_occurance)
        occurance = Common::Occurance.new new_occurance
        @amount = @occurance.generate_price_conversion(occurance).call(@amount)
        @occurance = occurance
      end

      def as_credit!
        @amount = -@amount
      end

      def as_debit!
        @amount = @amount.abs
      end

      def to_s
        "#{@description} (Category: #{@category}) #{@amount}, #{@occurance}"
      end

      def debit?
        @amount > 0
      end

      def credit?
        @amount < 0
      end

      def amount_for(occurance_type)
        target = Common::Occurance.new occurance_type
        proc_price = @occurance.generate_price_conversion target
        proc_price.call(@amount)
      end

      def ==(other)
        fail ArgumentError, ITEM_ERROR_MESSAGE unless other.instance_of?(Budget::Item)
        @description == other.description && @amount == other.amount &&
          @id == other.id && @category == other.category
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.10157257025006446, 'fraction_numerical': 0.007218355246197474, 'mean_word_length': 2.4094903339191562, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5253604', 'n_tokens_mistral': 1202, 'n_tokens_neox': 1115, 'n_words': 283}