Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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] - 2026-01-23
### Added
- Added `to_f` 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:
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
parameter_substitution (3.0.0)
parameter_substitution (3.1.0)
activesupport (>= 6.0)
builder (~> 3.2)
invoca-utils (~> 0.3)
Expand All @@ -22,7 +22,7 @@
tzinfo (~> 2.0)
appraisal (2.5.0)
bundler
rake

Check failure on line 25 in Gemfile.lock

View check run for this annotation

Security Scanner as a Service / Bundle Audit

Gemfile.lock#L25

thor Warning Message: https://github.com/advisories/GHSA-mqcp-p2hv-vw6x CVE: CVE-2025-54314 Severity: low
thor (>= 0.14.0)
appraisal-matrix (0.2.0)
appraisal (~> 2.2)
Expand Down
11 changes: 11 additions & 0 deletions lib/parameter_substitution/formatters/to_f.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 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)
Float(value).round(2) rescue nil
end
end
2 changes: 1 addition & 1 deletion lib/parameter_substitution/version.rb

Choose a reason for hiding this comment

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

We'll want to update this to the final release version prior to merging

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

class ParameterSubstitution
VERSION = "3.0.0"
VERSION = "3.1.0"
end
34 changes: 34 additions & 0 deletions spec/lib/parameter_substitution/formatters/to_f_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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 invalid strings" do
expect(@format_class.format(nil)).to eq(nil)
expect(@format_class.format("")).to eq(nil)
expect(@format_class.format("$123.4")).to eq(nil)
expect(@format_class.format("not_a_number")).to eq(nil)
end
end
end
Loading