From f692bbea3f3c1ed4c8cc56329684fa9e469e03b6 Mon Sep 17 00:00:00 2001 From: walterbloom11 Date: Fri, 23 Jan 2026 11:18:35 -0500 Subject: [PATCH 1/8] BIRDS-269: add new formatter and update version --- CHANGELOG.md | 4 ++++ Gemfile.lock | 2 +- lib/parameter_substitution/formatters/to_f.rb | 13 +++++++++++++ lib/parameter_substitution/version.rb | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 lib/parameter_substitution/formatters/to_f.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index d2e638b..d291b14 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.1.0.pre.1] - Not Released +### Added +- Added `string_to_float` formatter, which converts a string to a float value. + ## [3.0.0] - 2025-11-25 ### Added - Added optional context_overrides argument for the following methods: diff --git a/Gemfile.lock b/Gemfile.lock index 738b734..aa63084 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - parameter_substitution (3.0.0) + parameter_substitution (3.1.0.pre.1) activesupport (>= 6.0) builder (~> 3.2) invoca-utils (~> 0.3) diff --git a/lib/parameter_substitution/formatters/to_f.rb b/lib/parameter_substitution/formatters/to_f.rb new file mode 100644 index 0000000..f6a8a91 --- /dev/null +++ b/lib/parameter_substitution/formatters/to_f.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class ParameterSubstitution::Formatters::ToF < ParameterSubstitution::Formatters::Base + def self.description + "Converts a string to a double-precision floating point number" + end + + def self.format(value) + return nil if value.nil? || value.to_s.strip.empty? + + value.to_f.round(2) + end +end \ No newline at end of file diff --git a/lib/parameter_substitution/version.rb b/lib/parameter_substitution/version.rb index 8ca92eb..5fd4731 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.0.0" + VERSION = "3.1.0.pre.1" end From ce37972ce769d00cddb87a6e60e3817fad754227 Mon Sep 17 00:00:00 2001 From: walterbloom11 Date: Fri, 23 Jan 2026 11:24:57 -0500 Subject: [PATCH 2/8] BIRDS-269: update pre-release version --- Gemfile.lock | 2 +- lib/parameter_substitution/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index aa63084..d75e2d6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - parameter_substitution (3.1.0.pre.1) + parameter_substitution (3.1.0.wb.1) 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 5fd4731..0c6da41 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.pre.1" + VERSION = "3.1.0.wb.1" end From 505a3f1c2c3da36a7e78a2cebfe9c34d1b303f57 Mon Sep 17 00:00:00 2001 From: walterbloom11 Date: Fri, 23 Jan 2026 11:28:40 -0500 Subject: [PATCH 3/8] BIRDS-269: update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d291b14..71ea94a 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.1.0.pre.1] - Not Released +## [3.1.0.wb.1] - Not Released ### Added - Added `string_to_float` formatter, which converts a string to a float value. From 6d9cf0be4007f3db65ec9ae96a372419c629ec15 Mon Sep 17 00:00:00 2001 From: walterbloom11 Date: Fri, 23 Jan 2026 11:31:22 -0500 Subject: [PATCH 4/8] BIRDS-269: add tests --- .../formatters/to_f_spec.rb | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 spec/lib/parameter_substitution/formatters/to_f_spec.rb diff --git a/spec/lib/parameter_substitution/formatters/to_f_spec.rb b/spec/lib/parameter_substitution/formatters/to_f_spec.rb new file mode 100644 index 0000000..8aff5cf --- /dev/null +++ b/spec/lib/parameter_substitution/formatters/to_f_spec.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +require_relative '../../../../lib/parameter_substitution/formatters/to_f' + +describe ParameterSubstitution::Formatters::ToF do + context "ToF formatter test" do + before do + @format_class = ParameterSubstitution::Formatters::ToF + end + + it "have a key" do + expect(@format_class.key).to eq("to_f") + end + + it "provide a description" do + expect(@format_class.description).to eq("Converts a string to a double-precision floating point number") + end + + it "converts valid string to float rounded to 2 decimal places" do + expect(@format_class.format("123.456")).to eq(123.46) + expect(@format_class.format("0.001")).to eq(0.00) + expect(@format_class.format("-9876.54321")).to eq(-9876.54) + expect(@format_class.format("123")).to eq(123.0) + expect(@format_class.format("123.4")).to eq(123.4) + end + + it "returns nil for nil or empty strings" do + expect(@format_class.format(nil)).to eq(nil) + expect(@format_class.format("")).to eq(nil) + expect(@format_class.format(" ")).to eq(nil) + end + + it "returns 0.0 for invalid strings that cannot be converted" do + expect(@format_class.format("not_a_number")).to eq(0.0) + expect(@format_class.format("abc")).to eq(0.0) + end + end +end \ No newline at end of file From 4698b62fd6029fa1824cb5baf3378f44adf55bd3 Mon Sep 17 00:00:00 2001 From: walterbloom11 Date: Fri, 23 Jan 2026 14:51:50 -0500 Subject: [PATCH 5/8] BIRDS-269: make non-numeric strings nil rather than 0.0 --- Gemfile.lock | 2 +- lib/parameter_substitution/formatters/to_f.rb | 1 + lib/parameter_substitution/version.rb | 2 +- spec/lib/parameter_substitution/formatters/to_f_spec.rb | 6 +++--- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index d75e2d6..46eb258 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - parameter_substitution (3.1.0.wb.1) + parameter_substitution (3.1.0.wb.2) activesupport (>= 6.0) builder (~> 3.2) invoca-utils (~> 0.3) diff --git a/lib/parameter_substitution/formatters/to_f.rb b/lib/parameter_substitution/formatters/to_f.rb index f6a8a91..d1d6a31 100644 --- a/lib/parameter_substitution/formatters/to_f.rb +++ b/lib/parameter_substitution/formatters/to_f.rb @@ -7,6 +7,7 @@ def self.description def self.format(value) return nil if value.nil? || value.to_s.strip.empty? + return nil unless value.match?(/^\d+\.?\d*$/) value.to_f.round(2) end diff --git a/lib/parameter_substitution/version.rb b/lib/parameter_substitution/version.rb index 0c6da41..e163a03 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.wb.1" + VERSION = "3.1.0.wb.2" end diff --git a/spec/lib/parameter_substitution/formatters/to_f_spec.rb b/spec/lib/parameter_substitution/formatters/to_f_spec.rb index 8aff5cf..fba22ed 100644 --- a/spec/lib/parameter_substitution/formatters/to_f_spec.rb +++ b/spec/lib/parameter_substitution/formatters/to_f_spec.rb @@ -30,9 +30,9 @@ expect(@format_class.format(" ")).to eq(nil) end - it "returns 0.0 for invalid strings that cannot be converted" do - expect(@format_class.format("not_a_number")).to eq(0.0) - expect(@format_class.format("abc")).to eq(0.0) + it "returns nil for invalid strings that cannot be converted" do + expect(@format_class.format("not_a_number")).to eq(nil) + expect(@format_class.format("abc")).to eq(nil) end end end \ No newline at end of file From d4a786377a29c10be112b6ab7b82e02a17c6d973 Mon Sep 17 00:00:00 2001 From: walterbloom11 Date: Fri, 23 Jan 2026 15:06:59 -0500 Subject: [PATCH 6/8] BIRDS-269: update for cleanliness and readability --- Gemfile.lock | 2 +- lib/parameter_substitution/formatters/to_f.rb | 5 +---- lib/parameter_substitution/version.rb | 2 +- spec/lib/parameter_substitution/formatters/to_f_spec.rb | 8 ++------ 4 files changed, 5 insertions(+), 12 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 46eb258..a14d9de 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - parameter_substitution (3.1.0.wb.2) + parameter_substitution (3.1.0.wb.3) activesupport (>= 6.0) builder (~> 3.2) invoca-utils (~> 0.3) diff --git a/lib/parameter_substitution/formatters/to_f.rb b/lib/parameter_substitution/formatters/to_f.rb index d1d6a31..c9309b6 100644 --- a/lib/parameter_substitution/formatters/to_f.rb +++ b/lib/parameter_substitution/formatters/to_f.rb @@ -6,9 +6,6 @@ def self.description end def self.format(value) - return nil if value.nil? || value.to_s.strip.empty? - return nil unless value.match?(/^\d+\.?\d*$/) - - value.to_f.round(2) + Float(value).round(2) rescue nil end end \ No newline at end of file diff --git a/lib/parameter_substitution/version.rb b/lib/parameter_substitution/version.rb index e163a03..8041edf 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.wb.2" + VERSION = "3.1.0.wb.3" end diff --git a/spec/lib/parameter_substitution/formatters/to_f_spec.rb b/spec/lib/parameter_substitution/formatters/to_f_spec.rb index fba22ed..9d117f1 100644 --- a/spec/lib/parameter_substitution/formatters/to_f_spec.rb +++ b/spec/lib/parameter_substitution/formatters/to_f_spec.rb @@ -24,15 +24,11 @@ expect(@format_class.format("123.4")).to eq(123.4) end - it "returns nil for nil or empty strings" do + 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(" ")).to eq(nil) - end - - it "returns nil for invalid strings that cannot be converted" do + expect(@format_class.format("$123.4")).to eq(nil) expect(@format_class.format("not_a_number")).to eq(nil) - expect(@format_class.format("abc")).to eq(nil) end end end \ No newline at end of file From 6c7438f7c8e4b4bbb1f38e8aad7d2ef03d5816ea Mon Sep 17 00:00:00 2001 From: walterbloom11 Date: Fri, 23 Jan 2026 15:08:25 -0500 Subject: [PATCH 7/8] BIRDS-269: update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71ea94a..2bf58b0 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.1.0.wb.1] - Not Released ### Added -- Added `string_to_float` formatter, which converts a string to a float value. +- Added `to_f` formatter, which converts a string to a float value. ## [3.0.0] - 2025-11-25 ### Added From 50e4b834abf76f84f793bc62ddf18a21e307297d Mon Sep 17 00:00:00 2001 From: walterbloom11 Date: Fri, 23 Jan 2026 16:29:12 -0500 Subject: [PATCH 8/8] BIRDS-269: add real version and release date --- 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 2bf58b0..1cd27d5 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.1.0.wb.1] - Not Released +## [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 a14d9de..c57c30e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - parameter_substitution (3.1.0.wb.3) + parameter_substitution (3.1.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 8041edf..b42d1e9 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.wb.3" + VERSION = "3.1.0" end