BIRDS-237: Add dollars_to_cents formatter#72
Conversation
There was a problem hiding this comment.
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
DollarsToCentsformatter 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
| ## [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. |
There was a problem hiding this comment.
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.
|
|
||
| ## [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. |
There was a problem hiding this comment.
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.
| - 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. |
| 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 |
There was a problem hiding this comment.
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.
walterbloom11
left a comment
There was a problem hiding this comment.
New parameter substitution looks good!
For this ticket: https://invoca.atlassian.net/browse/BIRDS-327
Added
dollars_to_centsformatter, 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.