refactor: Deduplicate numericOnly helper in powerball and megamillions #13

Closed
opened 2026-02-14 16:06:33 +00:00 by Claude · 2 comments
Collaborator

Parent: #3

Description

Both sites/powerball/powerball.go:149-168 and sites/megamillions/megamillions.go:171-190 define identical numericOnly inline functions for parsing jackpot amounts:

numericOnly := func(in string) float64 {
    var out string
    for _, r := range in {
        if r >= '0' && r <= '9' {
            out += string(r)
        }
        if r == '.' {
            out += string(r)
        }
    }
    val, err := strconv.ParseFloat(out, 64)
    if err != nil {
        return 0
    }
    return val
}

Both also have identical jackpot multiplier logic for "Billion" and "Million" suffixes.

Fix

Extract a shared utility function, either in a sites/lottery package or as an exported function in the extractor package.

**Parent:** #3 ## Description Both `sites/powerball/powerball.go:149-168` and `sites/megamillions/megamillions.go:171-190` define identical `numericOnly` inline functions for parsing jackpot amounts: ```go numericOnly := func(in string) float64 { var out string for _, r := range in { if r >= '0' && r <= '9' { out += string(r) } if r == '.' { out += string(r) } } val, err := strconv.ParseFloat(out, 64) if err != nil { return 0 } return val } ``` Both also have identical jackpot multiplier logic for "Billion" and "Million" suffixes. ## Fix Extract a shared utility function, either in a `sites/lottery` package or as an exported function in the extractor package.
Claude added the priority/lowtype/refactor labels 2026-02-14 16:07:32 +00:00
Author
Collaborator

Starting work on this as part of PR 9 (also includes #14). Will extract numericOnly to sites/internal/parse/parse.go.

Starting work on this as part of PR 9 (also includes #14). Will extract `numericOnly` to `sites/internal/parse/parse.go`.
Author
Collaborator

Work finished — extracted identical numericOnly functions from powerball and megamillions into shared sites/internal/parse.NumericOnly with unit tests. Merged in PR #40.

Work finished — extracted identical `numericOnly` functions from powerball and megamillions into shared `sites/internal/parse.NumericOnly` with unit tests. Merged in PR #40.
Sign in to join this conversation.