Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.9.0 #59

Merged
merged 5 commits into from
Nov 6, 2023
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## [5.9.0](https://github.com/shivam091/unit_measurements/compare/v5.8.0...v5.9.0) - 2023-11-08

### What's new

- Added new units of `force`.
- Added new units of `torque`.
- Added new units of `energy`.

----------

## [5.8.0](https://github.com/shivam091/unit_measurements/compare/v5.7.0...v5.8.0) - 2023-11-06

### What's new
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:
unit_measurements (5.8.0)
unit_measurements (5.9.0)
activesupport (~> 7.0)

GEM
Expand Down
34 changes: 32 additions & 2 deletions lib/unit_measurements/unit_groups/energy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,48 @@
si_unit "cal", value: "4.1868 J", aliases: ["calorie", "calories"]

unit "eV", value: "1.602176634e-19 J", aliases: ["electronvolt", "electron volt", "electron-volt"]

unit "W⋅s", value: "1 J", aliases: ["W*s", "watt-second"]
unit "W⋅h", value: "3600 J", aliases: ["W*h", "watt-hour"]
unit "kW⋅h", value: "3.6e+6 J", aliases: ["kW*h", "kilowatt-hour"]
end

system :centimetre_gram_second do
unit "erg", value: "1e-7 J", aliases: ["ergs"]
end

system :us_customary do
si_unit "Btu", value: "1055.05585262 J", aliases: ["btu", "btus", "british thermal unit", "british thermal units"]
si_unit "BTU", value: "1055.05585262 J", aliases: ["Btu", "british thermal unit", "british thermal units"]

unit "thm", value: "100 kBtu", aliases: ["therm", "therms"]
unit "thm", value: "100 kBTU", aliases: ["therm", "therms"]
unit "quad", value: "1.05505585262e+18 J", aliases: ["quads"]

unit "ft⋅lbf", value: "1.3558179483314004 J", aliases: ["ft*lbf", "ft⋅lb", "ft*lb", "foot-pound force"]
unit "in⋅lbf", value: "0.1129848290276167 J", aliases: ["in*lbf", "in⋅lb", "in*lb", "inch-pound force"]
end

system :foot_pound_second do
unit "ft⋅pdl", value: "4.21401100938048e-2 J", aliases: ["ft*pdl", "foot-poundal"]
end

system :metre_tonne_second do
unit "th", value: "4.1868e+6 J", aliases: ["thermie", "thermies"]
end

system :gravitational_metric do
unit "kp⋅m", value: "9.80665 J", aliases: ["kpm", "kp*m", "kilopond-metre", "kilopond-meter"]
end

system :imperial do
unit "hp⋅h", value: "2.685e+13 erg", aliases: ["hp*h", "horsepower-hour"]
end

unit "Ry", value: "2.179872e-18 J", aliases: ["rydberg"]
unit "Ha", value: "4.359744e-18 J", aliases: ["hartree", "atomic unit of energy"]
unit "boe", value: "5.86152 GJ", aliases: ["barrel of oil equivalent", "barrels of oil equivalent"]
unit "tce", value: "29.3076 GJ", aliases: ["TCE", "tonne of coal equivalent", "tonnes of coal equivalent"]
unit "toe", value: "41.868 GJ", aliases: ["tonne of oil equivalent", "tonnes of oil equivalent"]
unit "foe", value: "1e+51 erg", aliases: ["bethe"]
unit "l⋅atm", value: "101.325 J", aliases: ["l*atm", "litre-atmosphere", "liter-atmosphere"]
unit "gal⋅atm", value: "460.63256925 J", aliases: ["gal*atm", "gallon-atmosphere"]
end
20 changes: 18 additions & 2 deletions lib/unit_measurements/unit_groups/force.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@
system :metric do
si_unit "N", aliases: ["newton", "newtons"]

unit "kgf", value: "9.80665 N", aliases: ["kilogram-force", "kilogramme-force"]
unit "p", value: "0.00980665 N", aliases: ["pond", "ponds"]
unit "gf", value: "0.00980665 N", aliases: ["gram-force", "gramme-force"]
unit "kgf", value: "9.80665 N", aliases: ["kp", "gvf", "kilogram-force", "kilogramme-force"]
unit "mgvf", value: "9.80665 mN", aliases: ["gvtf", "gravet-force", "milligrave-force"]
end

system :centimetre_gram_second do
unit "dyn", value: "1e-5 N", aliases: ["dyne", "dynes"]
end

system :metre_tonne_second do
unit "tf", value: "8896.443230521 N", aliases: ["tonne-force"]
unit "sn", value: "1e+3 N", aliases: ["sthene", "sthenes", "sthène"]
unit "tf", value: "8896.443230521 N", aliases: ["metric ton-force", "tonne-force"]
end

system :english_engineering do
Expand All @@ -27,4 +31,16 @@
unit "pdl", value: "0.138254954376 N", aliases: ["poundal", "poundals"]
unit "ozf", value: "0.27801385095378125 N", aliases: ["ounce-force"]
end

system :us_customary do
unit "tnf", value: "2000 lbf", aliases: ["ton-force", "short ton-force"]
unit "kipf", value: "4.4482216152605e+3 N", aliases: ["kip", "klbf", "kip-force"]
end

system :imperial do
unit "LTf", value: "2240 lbf", aliases: ["long ton-force"]
unit "(lb⋅m)/s²", value: "0.45359237 N", aliases: ["(lb*m)/s^2", "pound meter per second squared", "pound metre per second squared"]
unit "(lb⋅ft)/s²", value: "0.138254954376 N", aliases: ["(lb*ft)/s^2", "pound foot per second squared"]
unit "(lb⋅in)/s²", value: "0.011521246198 N", aliases: ["(lb*in)/s^2", "pound inch per second squared"]
end
end
11 changes: 11 additions & 0 deletions lib/unit_measurements/unit_groups/torque.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,22 @@
system :metric do
si_unit "N·m", aliases: ["N*m", "newton meter", "newton metre"]

unit "N·cm", value: "0.01 N·m", aliases: ["N*cm", "newton centimeter", "newton centimetre"]
unit "N·mm", value: "0.001 N·m", aliases: ["N*mm", "newton millimeter", "newton millimetre"]

unit "gf·m", value: "9.80665e-3 N·m", aliases: ["gf*m", "gram-force meter", "gramme-force metre"]
unit "gf·cm", value: "9.80665e-5 N·m", aliases: ["gf*cm", "gram-force centimeter", "gramme-force centimetre"]
unit "gf·mm", value: "9.80665e-6 N·m", aliases: ["gf*mm", "gram-force millimeter", "gramme-force millimetre"]

unit "kgf·m", value: "9.80665 N·m", aliases: ["kgf*m", "Kilogram-force meter", "kilogramme-force metre"]
unit "kgf·cm", value: "0.0980665 N·m", aliases: ["kgf*cm", "Kilogram-force centimeter", "kilogramme-force centimetre"]
unit "kgf·mm", value: "0.00980665 N·m", aliases: ["kgf*mm", "Kilogram-force millimeter", "kilogramme-force millimetre"]
end

system :centimetre_gram_second do
unit "dyn·m", value: "1e-5 N·m", aliases: ["dyn*m", "dyne meter", "dyne metre"]
unit "dyn·cm", value: "1e-7 N·m", aliases: ["dyn*cm", "dyne centimeter", "dyne centimetre"]
unit "dyn·mm", value: "1e-8 N·m", aliases: ["dyn*mm", "dyne millimeter", "dyne millimetre"]
end

system :foot_pound_second do
Expand Down
2 changes: 1 addition & 1 deletion lib/unit_measurements/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

module UnitMeasurements
# Current stable version.
VERSION = "5.8.0"
VERSION = "5.9.0"
end
86 changes: 75 additions & 11 deletions spec/unit_measurements/unit_groups/energy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,98 @@

RSpec.describe UnitMeasurements::Energy do
describe "J" do
subject { described_class.new(2, "J") }
subject { described_class.new(5, "J") }

it "converts to cal" do
expect(subject.convert_to("cal").quantity).to eq(0.477691793254992)
it "converts to eV" do
expect(subject.convert_to("eV").quantity).to eq(3.12075453723038e+19)
end

it "converts to eV" do
expect(subject.convert_to("eV").quantity).to eq(1.24830181489215e+19)
it "converts to Ry" do
expect(subject.convert_to("Ry").quantity).to eq(2.29371265835792e+18)
end

it "converts to Ha" do
expect(subject.convert_to("Ha").quantity).to eq(1.14685632917896e+18)
end

it "converts to th" do
expect(subject.convert_to("th").quantity).to eq(1.19422948313748e-06)
end

it "converts to toe" do
expect(subject.convert_to("toe").quantity).to eq(1.19422948313748e-10)
end

it "converts to tce" do
expect(subject.convert_to("tce").quantity).to eq(1.70604211876783e-10)
end

it "converts to foe" do
expect(subject.convert_to("foe").quantity).to eq(5e-44)
end

it "converts to boe" do
expect(subject.convert_to("boe").quantity).to eq(8.53021059383914e-10)
end

it "converts to cal" do
expect(subject.convert_to("cal").quantity).to eq(1.19422948313748)
end

it "converts to erg" do
expect(subject.convert_to("erg").quantity).to eq(2e+7)
expect(subject.convert_to("erg").quantity).to eq(50000000)
end

it "converts to Btu" do
expect(subject.convert_to("Btu").quantity).to eq(0.00189563424062663)
expect(subject.convert_to("Btu").quantity).to eq(0.00473908560156659)
end

it "converts to thm" do
expect(subject.convert_to("thm").quantity).to eq(1.89563424062663e-8)
expect(subject.convert_to("thm").quantity).to eq(4.73908560156659e-8)
end

it "converts to W⋅s" do
expect(subject.convert_to("W⋅s").quantity).to eq(5)
end

it "converts to W⋅h" do
expect(subject.convert_to("W⋅h").quantity).to eq(0.00138888888888889)
end

it "converts to quad" do
expect(subject.convert_to("quad").quantity).to eq(1.89563424062663e-18)
expect(subject.convert_to("quad").quantity).to eq(4.73908560156659e-18)
end

it "converts to foe" do
expect(subject.convert_to("foe").quantity).to eq(2e-44)
it "converts to kW⋅h" do
expect(subject.convert_to("kW⋅h").quantity).to eq(1.38888888888889e-6)
end

it "converts to kp⋅m" do
expect(subject.convert_to("kp⋅m").quantity).to eq(0.509858106488964)
end

it "converts to hp⋅h" do
expect(subject.convert_to("hp⋅h").quantity).to eq(1.86219739292365e-6)
end

it "converts to l⋅atm" do
expect(subject.convert_to("l⋅atm").quantity).to eq(0.0493461633358006)
end

it "converts to ft⋅lbf" do
expect(subject.convert_to("ft⋅lbf").quantity).to eq(3.68781074638633)
end

it "converts to in⋅lbf" do
expect(subject.convert_to("in⋅lbf").quantity).to eq(44.2537289566359)
end

it "converts to ft⋅pdl" do
expect(subject.convert_to("ft⋅pdl").quantity).to eq(118.65180202116)
end

it "converts to gal⋅atm" do
expect(subject.convert_to("gal⋅atm").quantity).to eq(0.0108546384554201)
end
end
end
58 changes: 49 additions & 9 deletions spec/unit_measurements/unit_groups/force_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,70 @@

RSpec.describe UnitMeasurements::Force do
describe "N" do
subject { described_class.new(2, "N") }
subject { described_class.new(5, "N") }

it "converts to p" do
expect(subject.convert_to("p").quantity).to eq(509.858106488964)
end

it "converts to gf" do
expect(subject.convert_to("gf").quantity).to eq(509.858106488964)
end

it "converts to tf" do
expect(subject.convert_to("tf").quantity).to eq(0.000562022357749276)
end

it "converts to sn" do
expect(subject.convert_to("sn").quantity).to eq(0.005)
end

it "converts to dyn" do
expect(subject.convert_to("dyn").quantity).to eq(2e+5)
expect(subject.convert_to("dyn").quantity).to eq(5e+5)
end

it "converts to kgf" do
expect(subject.convert_to("kgf").quantity).to eq(0.203943242595586)
expect(subject.convert_to("kgf").quantity).to eq(0.509858106488964)
end

it "converts to ozf" do
expect(subject.convert_to("ozf").quantity).to eq(7.19388617919074)
expect(subject.convert_to("ozf").quantity).to eq(17.9847154479768)
end

it "converts to lbf" do
expect(subject.convert_to("lbf").quantity).to eq(0.449617886199421)
expect(subject.convert_to("lbf").quantity).to eq(1.12404471549855)
end

it "converts to tf" do
expect(subject.convert_to("tf").quantity).to eq(0.000224808943099711)
it "converts to pdl" do
expect(subject.convert_to("pdl").quantity).to eq(36.1650692560495)
end

it "converts to pdl" do
expect(subject.convert_to("pdl").quantity).to eq(14.4660277024198)
it "converts to tnf" do
expect(subject.convert_to("tnf").quantity).to eq(0.000562022357749276)
end

it "converts to LTf" do
expect(subject.convert_to("LTf").quantity).to eq(0.000501805676561854)
end

it "converts to mgvf" do
expect(subject.convert_to("mgvf").quantity).to eq(509.858106488964)
end

it "converts to kipf" do
expect(subject.convert_to("kipf").quantity).to eq(0.00112404471549855)
end

it "converts to (lb⋅m)/s²" do
expect(subject.convert_to("(lb⋅m)/s²").quantity).to eq(11.0231131092439)
end

it "converts to (lb⋅ft)/s²" do
expect(subject.convert_to("(lb⋅ft)/s²").quantity).to eq(36.1650692560495)
end

it "converts to (lb⋅in)/s²" do
expect(subject.convert_to("(lb⋅in)/s²").quantity).to eq(433.980831072594)
end
end
end
40 changes: 40 additions & 0 deletions spec/unit_measurements/unit_groups/torque_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,50 @@
describe "N·m" do
subject { described_class.new(5, "N·m") }

it "converts to N·cm" do
expect(subject.convert_to("N·cm").quantity).to eq(500)
end

it "converts to N·mm" do
expect(subject.convert_to("N·mm").quantity).to eq(5000)
end

it "converts to gf·m" do
expect(subject.convert_to("gf·m").quantity).to eq(509.858106488964)
end

it "converts to gf·cm" do
expect(subject.convert_to("gf·cm").quantity).to eq(50985.8106488964)
end

it "converts to gf·mm" do
expect(subject.convert_to("gf·mm").quantity).to eq(5.09858106488964e+5)
end

it "converts to kgf·m" do
expect(subject.convert_to("kgf·m").quantity).to eq(0.509858106488964)
end

it "converts to kgf·cm" do
expect(subject.convert_to("kgf·cm").quantity).to eq(50.9858106488964)
end

it "converts to kgf·mm" do
expect(subject.convert_to("kgf·mm").quantity).to eq(509.858106488964)
end

it "converts to dyn·m" do
expect(subject.convert_to("dyn·m").quantity).to eq(5e+5)
end

it "converts to dyn·cm" do
expect(subject.convert_to("dyn·cm").quantity).to eq(5e+7)
end

it "converts to dyn·mm" do
expect(subject.convert_to("dyn·mm").quantity).to eq(5e+8)
end

it "converts to lbf⋅in" do
expect(subject.convert_to("lbf⋅in").quantity).to eq(44.2537289566359)
end
Expand All @@ -31,5 +67,9 @@
it "converts to ozf·in" do
expect(subject.convert_to("ozf·in").quantity).to eq(708.059845218118)
end

it "converts to ozf·ft" do
expect(subject.convert_to("ozf·ft").quantity).to eq(59.0049871015098)
end
end
end
Loading