Skip to content

Comments

BIRDS-237: Add dollars_to_cents formatter#72

Open
earl-at-invoca wants to merge 2 commits intomasterfrom
BIRDS-327-dollars_to_cents
Open

BIRDS-237: Add dollars_to_cents formatter#72
earl-at-invoca wants to merge 2 commits intomasterfrom
BIRDS-327-dollars_to_cents

Conversation

@earl-at-invoca
Copy link

For this ticket: https://invoca.atlassian.net/browse/BIRDS-327

Added dollars_to_cents formatter, which converts a string representing a dollar amount to an integer representing the equivalent amount in cents. For example, "12.34" would be converted to 1234.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new dollars_to_cents formatter that converts dollar amounts (as strings or numbers) to their equivalent value in cents as an integer. The implementation follows existing formatter patterns in the codebase, using inline error handling and auto-discovery through the formatters directory.

Changes:

  • Added DollarsToCents formatter class with conversion logic using Float multiplication and rounding
  • Added comprehensive test suite covering string inputs, numeric inputs, and invalid inputs
  • Updated version from 3.1.0 to 3.2.0.pre.1 (appropriate minor version bump)
  • Added changelog entry documenting the new formatter

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
lib/parameter_substitution/formatters/dollars_to_cents.rb Implements the formatter using Float conversion, multiplication by 100, and rounding to integer
spec/lib/parameter_substitution/formatters/dollars_to_cents_spec.rb Comprehensive test suite covering valid/invalid inputs, strings/numerics, and edge cases
lib/parameter_substitution/version.rb Version bump to 3.2.0.pre.1 for new feature
Gemfile.lock Lockfile update reflecting new version
CHANGELOG.md Documents the new formatter feature

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

CHANGELOG.md Outdated
Comment on lines 7 to 9
## [3.2.0] - not released
### Added
- Added `dollars_to_cents` formatter, which converts a string representing a dollar amount to an integer representing the equivalent amount in cents. For example, "12.34" would be converted to 1234.
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a discrepancy between the PR title and description. The title references "BIRDS-237" but the PR description links to "BIRDS-327". Please verify which ticket number is correct and update accordingly.

Copilot uses AI. Check for mistakes.

## [3.2.0] - not released
### Added
- Added `dollars_to_cents` formatter, which converts a string representing a dollar amount to an integer representing the equivalent amount in cents. For example, "12.34" would be converted to 1234.
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changelog description states this formatter "converts a string representing a dollar amount" but the implementation and tests also handle numeric inputs (integers and floats). Consider updating the changelog to reflect that both string and numeric inputs are supported, similar to how the implementation description in the code says "Converts a dollar amount to cents as an integer" without limiting it to strings.

Suggested change
- Added `dollars_to_cents` formatter, which converts a string representing a dollar amount to an integer representing the equivalent amount in cents. For example, "12.34" would be converted to 1234.
- Added `dollars_to_cents` formatter, which converts a dollar amount (provided as a string or numeric value) to an integer representing the equivalent amount in cents. For example, "12.34" would be converted to 1234.

Copilot uses AI. Check for mistakes.
Comment on lines +30 to +39
it "converts valid numeric dollar amounts to cents" do
expect(@format_class.format(10.50)).to eq(1050)
expect(@format_class.format(10)).to eq(1000)
expect(@format_class.format(0.01)).to eq(1)
expect(@format_class.format(123.456)).to eq(12346)
expect(@format_class.format(0.001)).to eq(0)
expect(@format_class.format(100)).to eq(10000)
expect(@format_class.format(99.99)).to eq(9999)
expect(@format_class.format(-10.50)).to eq(-1050)
end
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding test cases for edge values that test rounding at exactly 0.5 cents, such as "0.005" (should round to 1) and "0.015" (should round to 2), to explicitly verify and document the rounding behavior when the fractional cent is exactly at the midpoint.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@walterbloom11 walterbloom11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New parameter substitution looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants