Class: FindSubscriptions::Detectors::RepeatCharges
- Inherits:
-
Object
- Object
- FindSubscriptions::Detectors::RepeatCharges
- Defined in:
- lib/detectors/repeat_charges.rb
Overview
Detects recurring charges by grouping outgoing transactions by normalized payee and amount.
Defined Under Namespace
Classes: Candidate
Instance Method Summary collapse
- #detect(transactions) ⇒ Object
-
#initialize(payee_normalizer:, min_occurrences: 2, min_month_gap_days: 0, max_month_gap_days: 1000) ⇒ RepeatCharges
constructor
rubocop:enable Lint/StructNewOverride.
Constructor Details
#initialize(payee_normalizer:, min_occurrences: 2, min_month_gap_days: 0, max_month_gap_days: 1000) ⇒ RepeatCharges
rubocop:enable Lint/StructNewOverride
20 21 22 23 24 25 |
# File 'lib/detectors/repeat_charges.rb', line 20 def initialize(payee_normalizer:, min_occurrences: 2, min_month_gap_days: 0, max_month_gap_days: 1000) @payee_normalizer = payee_normalizer @min_occurrences = min_occurrences @min_gap = min_month_gap_days @max_gap = max_month_gap_days end |
Instance Method Details
#detect(transactions) ⇒ Object
27 28 29 30 31 |
# File 'lib/detectors/repeat_charges.rb', line 27 def detect(transactions) outgoing = transactions.select { |t| t.amount&.positive? } groups = outgoing.group_by { |t| [@payee_normalizer.normalize(t.payee), t.amount] } groups.filter_map { |(payee_key, amount), txs| build_candidate(payee_key, amount, txs) } end |