From ab4bda89b085166fded4b9b60d07ac1ab91116de Mon Sep 17 00:00:00 2001 From: Earl Jenkins Date: Tue, 17 Feb 2026 09:46:40 -0800 Subject: [PATCH 1/3] BIRDS-237: Add dollars_to_cents formatter --- CHANGELOG.md | 4 ++ Gemfile.lock | 2 +- .../formatters/dollars_to_cents.rb | 11 +++++ lib/parameter_substitution/version.rb | 2 +- .../formatters/dollars_to_cents_spec.rb | 48 +++++++++++++++++++ 5 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 lib/parameter_substitution/formatters/dollars_to_cents.rb create mode 100644 spec/lib/parameter_substitution/formatters/dollars_to_cents_spec.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cd27d5..a47c326 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). Note: This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [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. + ## [3.1.0] - 2026-01-23 ### Added - Added `to_f` formatter, which converts a string to a float value. diff --git a/Gemfile.lock b/Gemfile.lock index c57c30e..0115387 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - parameter_substitution (3.1.0) + parameter_substitution (3.2.0.pre.1) activesupport (>= 6.0) builder (~> 3.2) invoca-utils (~> 0.3) diff --git a/lib/parameter_substitution/formatters/dollars_to_cents.rb b/lib/parameter_substitution/formatters/dollars_to_cents.rb new file mode 100644 index 0000000..163d518 --- /dev/null +++ b/lib/parameter_substitution/formatters/dollars_to_cents.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class ParameterSubstitution::Formatters::DollarsToCents < ParameterSubstitution::Formatters::Base + def self.description + "Converts a dollar amount to cents as an integer" + end + + def self.format(value) + (Float(value) * 100).round.to_i rescue nil + end +end diff --git a/lib/parameter_substitution/version.rb b/lib/parameter_substitution/version.rb index b42d1e9..cbd783e 100644 --- a/lib/parameter_substitution/version.rb +++ b/lib/parameter_substitution/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true class ParameterSubstitution - VERSION = "3.1.0" + VERSION = "3.2.0.pre.1" end diff --git a/spec/lib/parameter_substitution/formatters/dollars_to_cents_spec.rb b/spec/lib/parameter_substitution/formatters/dollars_to_cents_spec.rb new file mode 100644 index 0000000..87a038a --- /dev/null +++ b/spec/lib/parameter_substitution/formatters/dollars_to_cents_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require_relative '../../../../lib/parameter_substitution/formatters/dollars_to_cents' + +describe ParameterSubstitution::Formatters::DollarsToCents do + context "DollarsToCents formatter test" do + before do + @format_class = ParameterSubstitution::Formatters::DollarsToCents + end + + it "have a key" do + expect(@format_class.key).to eq("dollars_to_cents") + end + + it "provide a description" do + expect(@format_class.description).to eq("Converts a dollar amount to cents as an integer") + end + + it "converts valid string 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 + + 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 + + it "returns nil for nil or invalid strings" do + expect(@format_class.format(nil)).to eq(nil) + expect(@format_class.format("")).to eq(nil) + expect(@format_class.format("$10.50")).to eq(nil) + expect(@format_class.format("not_a_number")).to eq(nil) + end + end +end From c51f4351e991f100c37d3fb8e54c41168ebef990 Mon Sep 17 00:00:00 2001 From: Earl Jenkins Date: Tue, 24 Feb 2026 16:12:45 -0800 Subject: [PATCH 2/3] BIRDS-327: Update version to release 3.3.0 --- CHANGELOG.md | 2 +- Gemfile.lock | 2 +- lib/parameter_substitution/version.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb533ad..740ef3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). Note: This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [3.3.0] - not released +## [3.3.0] - 2026-02-24 ### 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. diff --git a/Gemfile.lock b/Gemfile.lock index ecedf9a..f7497b9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - parameter_substitution (3.3.0.pre.1) + parameter_substitution (3.3.0) activesupport (>= 6.0) builder (~> 3.2) invoca-utils (~> 0.3) diff --git a/lib/parameter_substitution/version.rb b/lib/parameter_substitution/version.rb index 4fde6b8..5323fa4 100644 --- a/lib/parameter_substitution/version.rb +++ b/lib/parameter_substitution/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true class ParameterSubstitution - VERSION = "3.3.0.pre.1" + VERSION = "3.3.0" end From 76b02549941afb4e8e68be3129c08624d14bf309 Mon Sep 17 00:00:00 2001 From: Earl Jenkins Date: Tue, 24 Feb 2026 16:16:42 -0800 Subject: [PATCH 3/3] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 740ef3b..70f9a55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ Note: This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0 ## [3.3.0] - 2026-02-24 ### 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. +- 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. ## [3.2.0] - 2026-02-19 ### Added