Skip to content

Add Measured::Temperature unit type#189

Open
ntn wants to merge 1 commit intofunctional-conversionsfrom
add-temperature-type-v2
Open

Add Measured::Temperature unit type#189
ntn wants to merge 1 commit intofunctional-conversionsfrom
add-temperature-type-v2

Conversation

@ntn
Copy link
Contributor

@ntn ntn commented Mar 10, 2026

Summary

Adds Measured::Temperature as the first functional unit type, demonstrating the proc-based conversion system from #188.

Includes three units:

  • Celsius (C) - base unit
  • Kelvin (K) - celsius + 273.15
  • Fahrenheit (F) - celsius * 9/5 + 32

Opt-in only

Temperature is not included in the default require "measured". Users opt in explicitly:

# In Gemfile
gem 'measured', require: ['measured', 'measured/temperature']

# Or manually
require 'measured/temperature'

This keeps the default gem lightweight and avoids loading functional conversion infrastructure for users who only need static units (length, weight, volume).

Usage

require 'measured/temperature'

temp = Measured::Temperature.new(100, :C)
temp.convert_to(:F)  # => 212 F
temp.convert_to(:K)  # => 373.15 K

Measured::Temperature.new(0, :K).convert_to(:C)  # => -273.15 C

Test plan

  • All temperature conversions (C↔K, C↔F, K↔F, identity, negatives, indirect paths)
  • Arithmetic and comparison across units
  • Existing unit tests (length, weight, volume) unaffected
  • require 'measured' alone does not load Temperature

@ntn ntn self-assigned this Mar 10, 2026
@ntn ntn marked this pull request as draft March 10, 2026 03:24
@ntn ntn force-pushed the add-temperature-type-v2 branch from b56e8c3 to 7128403 Compare March 10, 2026 03:24
Copy link
Contributor

@kmcphillips kmcphillips left a comment

Choose a reason for hiding this comment

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

Clean 👌

@ntn ntn force-pushed the functional-conversions branch from c6f7bb1 to 98d49fe Compare March 10, 2026 20:46
@ntn ntn force-pushed the add-temperature-type-v2 branch from 7128403 to 778c416 Compare March 10, 2026 20:47
@ntn ntn force-pushed the functional-conversions branch from 98d49fe to 3a53018 Compare March 10, 2026 21:01
@ntn ntn force-pushed the add-temperature-type-v2 branch from 778c416 to 1093f33 Compare March 10, 2026 21:02
@ntn ntn force-pushed the functional-conversions branch from 3a53018 to 1631f10 Compare March 10, 2026 21:09
@ntn ntn force-pushed the add-temperature-type-v2 branch 3 times, most recently from 3b545ad to 77a033f Compare March 10, 2026 21:19
Add Temperature as an opt-in unit type with Celsius, Kelvin, and
Fahrenheit. Not included in the default require - users opt in with:

  gem 'measured', require: ['measured', 'measured/temperature']

Or manually: require 'measured/temperature'
@ntn ntn force-pushed the add-temperature-type-v2 branch from 77a033f to 1977700 Compare March 10, 2026 21:22
@ntn ntn marked this pull request as ready for review March 10, 2026 21:23
Combustion.path = "test/internal"
Combustion.initialize! :active_record, :active_model
require "measured"
require "measured/all"
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah this is better!

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