diff --git a/CHANGELOG.md b/CHANGELOG.md index 454e2e8..c120107 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +## [5.19.0](https://github.com/shivam091/unit_measurements/compare/v5.18.0...v5.19.0) - 2025-01-12 + +### What's new + +- Added US Customary units for square foot (`sq_ft`), square mile (`sq_mi`), and square chain (`sq_ch`). + +### What's changed + +- Changed symbol of units `cb (M)` and `cb (US)` to `metric_cb` and `us_cb` in `length`. +- Changed symbol of unit `hp (M)` to `metric_hp` in `power`. +- Changed symbol of unit `cwt (US)` to `us_cwt` in `weight`. + +---------- + ## [5.18.0](https://github.com/shivam091/unit_measurements/compare/v5.17.0...v5.18.0) - 2023-12-16 ### What's new diff --git a/Gemfile.lock b/Gemfile.lock index 5cb657d..c884ec7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - unit_measurements (5.18.0) + unit_measurements (5.19.0) activesupport (~> 7.0) GEM diff --git a/lib/unit_measurements/unit.rb b/lib/unit_measurements/unit.rb index 8d43cf5..bb55288 100644 --- a/lib/unit_measurements/unit.rb +++ b/lib/unit_measurements/unit.rb @@ -202,6 +202,14 @@ def conversion_factor ["Q", %w[quetta], 1e+30] ].map(&:freeze).freeze + # Prefixes for SI binary units and SI decimal units. + # + # @see SI_BINARY_PREFIXES + # @see SI_DECIMAL_PREFIXES + # @author {Harshal V. Ladhe}[https://shivam091.github.io/] + # @since 5.19.0 + SI_PREFIXES = SI_BINARY_PREFIXES + SI_DECIMAL_PREFIXES + # Parses tokens and returns a +conversion value+ and the +unit+. # # This method is used internally to parse the conversion value of the unit diff --git a/lib/unit_measurements/unit_group_builder.rb b/lib/unit_measurements/unit_group_builder.rb index 4db0d45..86f5482 100644 --- a/lib/unit_measurements/unit_group_builder.rb +++ b/lib/unit_measurements/unit_group_builder.rb @@ -165,7 +165,7 @@ def cache(cache_file) def build_si_units(name, value:, add_binary_prefixes:, aliases:) si_units = [build_unit(name, value: value, aliases: aliases)] - si_prefixes = add_binary_prefixes ? (Unit::SI_DECIMAL_PREFIXES + Unit::SI_BINARY_PREFIXES) : Unit::SI_DECIMAL_PREFIXES + si_prefixes = add_binary_prefixes ? Unit::SI_PREFIXES : Unit::SI_DECIMAL_PREFIXES si_prefixes.each do |short_prefix, long_prefix, multiplier| si_aliases = long_prefix.product(aliases.to_a).flat_map do |prefix, unit| diff --git a/lib/unit_measurements/unit_groups/area.rb b/lib/unit_measurements/unit_groups/area.rb index 8904e85..61bcb03 100644 --- a/lib/unit_measurements/unit_groups/area.rb +++ b/lib/unit_measurements/unit_groups/area.rb @@ -34,10 +34,14 @@ unit "sec", value: "640 ac", aliases: ["sect", "section", "sections"] unit "twp", value: "36 sec", aliases: ["survey township", "survey townships"] - unit "ac (US)", value: "4046.873 m²", aliases: ["acre (US)", "acres (US)"] + unit "us_ac", value: "4046.873 m²", aliases: ["us acre", "us acres"] unit "ft² (US)", value: "0.09290341161327482 m²", aliases: ["ft^2 (US)", "sq ft (US)", "square foot (US)", "square feet (US)"] unit "mi² (US)", value: "2.58999847e+6 m²", aliases: ["mi^2 (US)", "sq mi (US)", "square mile (US)", "square miles (US)"] unit "ch² (US)", value: "404.6873 m²", aliases: ["ch^2 (US)", "sq ch (US)", "square chain (US)", "square chains (US)"] + + unit "sq_ft", value: "0.09290341161327482 m²", aliases: ["us square foot", "us square feet"] + unit "sq_mi", value: "2.58999847e+6 m²", aliases: ["us square mile", "us square miles"] + unit "sq_ch", value: "404.6873 m²", aliases: ["us square chain", "us square chains"] end system :planck_units do diff --git a/lib/unit_measurements/unit_groups/length.rb b/lib/unit_measurements/unit_groups/length.rb index b4ac6a1..05b0f41 100644 --- a/lib/unit_measurements/unit_groups/length.rb +++ b/lib/unit_measurements/unit_groups/length.rb @@ -11,7 +11,7 @@ unit "Å", value: "1e-10 m", aliases: ["angstrom", "angstroms", "ångström"] unit "μ", value: "1 μm", aliases: ["micron", "microns"] - unit "cb (M)", value: "185.2 m", aliases: ["CBL. (M)", "cable length (M)"] + unit "metric_cb", value: "185.2 m", aliases: ["metric cable length"] end system :imperial do @@ -25,7 +25,7 @@ unit "th", value: "1/1000 in", aliases: ["thou", "thousandth of an inch", "mil", "mils"] unit "nl", value: "3 nmi", aliases: ["NL", "nleague", "nleagues", "nautical league", "nautical leagues"] unit "rd", value: "16 1/2 ft", aliases: ["rod", "rods", "perch", "pole", "lug"] - unit "cb", value: "608 ft", aliases: ["CBL.", "cable length"] + unit "cb", value: "608 ft", aliases: ["cable length"] unit "qr", value: "1/4 yd", aliases: ["quarter", "quarters"] unit "bc", value: "1/3 in", aliases: ["b.c.", "barleycorn", "barleycorns"] @@ -41,7 +41,7 @@ unit "U", value: "1.75 in", aliases: ["RU", "rack unit", "rack units"] unit "sft", value: "1200/3937 m", aliases: ["sfoot", "sfeet", "survey-foot", "survey-feet"] - unit "cb (US)", value: "720 ft", aliases: ["CBL. (US)", "cable length (US)"] + unit "us_cb", value: "720 ft", aliases: ["us cable length"] end system :astronomical do diff --git a/lib/unit_measurements/unit_groups/power.rb b/lib/unit_measurements/unit_groups/power.rb index 1ddd2f6..cd5c7c8 100644 --- a/lib/unit_measurements/unit_groups/power.rb +++ b/lib/unit_measurements/unit_groups/power.rb @@ -10,7 +10,7 @@ unit "p", value: "980.665 W", aliases: ["poncelet", "poncelets"] - unit "hp (M)", value: "735.49875 W", aliases: ["PS", "metric horsepower"] + unit "metric_hp", value: "735.49875 W", aliases: ["PS", "metric horsepower"] unit "kgf⋅m", value: "9.80665 W", aliases: ["kgf*m", "kilogramme-force meter", "kilogram-force meter"] unit "erg/s", value: "1e-7 W", aliases: ["erg per second", "ergs per second"] diff --git a/lib/unit_measurements/unit_groups/weight.rb b/lib/unit_measurements/unit_groups/weight.rb index 72f91b7..5aa60a6 100644 --- a/lib/unit_measurements/unit_groups/weight.rb +++ b/lib/unit_measurements/unit_groups/weight.rb @@ -37,8 +37,8 @@ system :us_customary do unit "tn", value: "2000 lb", aliases: ["ton", "tons", "short ton", "short tons"] - unit "us qr", value: "1/4 cwt (US)", aliases: ["us qtr", "us quarter", "us quarters"] - unit "cwt (US)", value: "100 lb", aliases: ["hundredweight (US)", "short hundredweight"] + unit "us_qr", value: "1/4 us_cwt", aliases: ["us qtr", "us quarter", "us quarters"] + unit "us_cwt", value: "100 lb", aliases: ["us hundredweight", "short hundredweight"] end system :gravitational_metric do diff --git a/lib/unit_measurements/version.rb b/lib/unit_measurements/version.rb index cdc979f..ec8c945 100644 --- a/lib/unit_measurements/version.rb +++ b/lib/unit_measurements/version.rb @@ -4,5 +4,5 @@ module UnitMeasurements # Current stable version. - VERSION = "5.18.0" + VERSION = "5.19.0" end diff --git a/spec/unit_measurements/unit_groups/area_spec.rb b/spec/unit_measurements/unit_groups/area_spec.rb index 17c06b5..1eda937 100644 --- a/spec/unit_measurements/unit_groups/area_spec.rb +++ b/spec/unit_measurements/unit_groups/area_spec.rb @@ -80,8 +80,8 @@ expect(subject.convert_to("lnk²").quantity).to eq(123.552690733583) end - it "converts to ac (US)" do - expect(subject.convert_to("ac (US)").quantity).to eq(0.00123552184612663) + it "converts to us_ac" do + expect(subject.convert_to("us_ac").quantity).to eq(0.00123552184612663) end it "converts to ft² (US)" do @@ -99,5 +99,17 @@ it "converts to Aₚ" do expect(subject.convert_to("Aₚ").quantity).to eq(1.91416867654378e+70) end + + it "converts to sq_ft" do + expect(subject.convert_to("sq_ft").quantity).to eq(0.538193368055556e2) + end + + it "converts to sq_mi" do + expect(subject.convert_to("sq_mi").quantity).to eq(0.193050307091494e-5) + end + + it "converts to sq_ch" do + expect(subject.convert_to("sq_ch").quantity).to eq(0.123552184612663e-1) + end end end diff --git a/spec/unit_measurements/unit_groups/length_spec.rb b/spec/unit_measurements/unit_groups/length_spec.rb index 6292a80..06bfcfd 100644 --- a/spec/unit_measurements/unit_groups/length_spec.rb +++ b/spec/unit_measurements/unit_groups/length_spec.rb @@ -136,12 +136,12 @@ expect(subject.convert_to("bc").quantity).to eq(590.551181102362) end - it "converts to cb (M)" do - expect(subject.convert_to("cb (M)").quantity).to eq(0.0269978401727862) + it "converts to metric_cb" do + expect(subject.convert_to("metric_cb").quantity).to eq(0.0269978401727862) end - it "converts to cb (US)" do - expect(subject.convert_to("cb (US)").quantity).to eq(0.0227836103820356) + it "converts to us_cb" do + expect(subject.convert_to("us_cb").quantity).to eq(0.0227836103820356) end it "converts to lₚ" do diff --git a/spec/unit_measurements/unit_groups/power_spec.rb b/spec/unit_measurements/unit_groups/power_spec.rb index a86c062..d3623fb 100644 --- a/spec/unit_measurements/unit_groups/power_spec.rb +++ b/spec/unit_measurements/unit_groups/power_spec.rb @@ -16,8 +16,8 @@ expect(subject.convert_to("hp").quantity).to eq(0.00670511044797514) end - it "converts to hp (M)" do - expect(subject.convert_to("hp (M)").quantity).to eq(0.00679810808651952) + it "converts to metric_hp" do + expect(subject.convert_to("metric_hp").quantity).to eq(0.00679810808651952) end it "converts to kgf⋅m" do diff --git a/spec/unit_measurements/unit_groups/weight_spec.rb b/spec/unit_measurements/unit_groups/weight_spec.rb index c5f0c10..7b7487f 100644 --- a/spec/unit_measurements/unit_groups/weight_spec.rb +++ b/spec/unit_measurements/unit_groups/weight_spec.rb @@ -92,16 +92,16 @@ expect(subject.convert_to("fir").quantity).to eq(0.196841305522212) end - it "converts to us qr" do - expect(subject.convert_to("us qr").quantity).to eq(0.440924524369755) + it "converts to us_qr" do + expect(subject.convert_to("us_qr").quantity).to eq(0.440924524369755) end it "converts to slug" do expect(subject.convert_to("slug").quantity).to eq(0.342608829245948) end - it "converts to cwt (US)" do - expect(subject.convert_to("cwt (US)").quantity).to eq(0.110231131092439) + it "converts to us_cwt" do + expect(subject.convert_to("us_cwt").quantity).to eq(0.110231131092439) end it "converts to mₚ" do diff --git a/units.md b/units.md index fe2720b..d5f4168 100644 --- a/units.md +++ b/units.md @@ -32,7 +32,7 @@ These units are defined in `UnitMeasurements::Length`. | 13 | pc | parsec, parsecs | | 14 | nl | NL, nleague, nleagues, nautical league, nautical leagues | | 15 | rd | rod, rods, perch, pole, lug | -| 16 | cb | CBL., cable length | +| 16 | cb | cable length | | 17 | ls | light-second, light-seconds | | 18 | lh | light-hour, light-hours | | 19 | ld | light-day, light-days | @@ -47,8 +47,8 @@ These units are defined in `UnitMeasurements::Length`. | 28 | sft | sfoot, sfeet, survey-foot, survey-feet | | 29 | bc | b.c., barleycorn, barleycorns | | 30 | lmin | light-minute, light-minutes | -| 31 | cb (M) | CBL. (M), cable length (M) | -| 32 | cb (US) | CBL. (US), cable length (US) | +| 31 | metric_cb | metric cable length | +| 32 | us_cb | us cable length | | 33 | lₚ | planck length, quantum length | | 34 | qr | quarter, quarters | | 35 | U | RU, rack unit, rack units | @@ -81,11 +81,11 @@ These units are defined in `UnitMeasurements::Weight`. | 19 | hyl | mug, metric slug, metric slugs, hyls | | 20 | cwt | hundredweight, long hundredweight, imperial hundredweight | | 21 | slug | slugs | -| 22 | cwt (US) | hundredweight (US), short hundredweight | +| 22 | us_cwt | us hundredweight, short hundredweight | | 23 | mₚ | planck mass, quantum mass | | 24 | qr | qtr, quarter, quarters | | 25 | fir | firkin, firkins | -| 26 | us qr | us qtr, us quarter, us quarters | +| 26 | us_qr | us qtr, us quarter, us quarters | ## 3. Time or duration @@ -168,7 +168,7 @@ These units are defined in `UnitMeasurements::Area`. | 14 | fur² | fur^2, sq fur, square furlong, square furlongs | | 15 | rd² | rd^2, sq rd, square rod, square rods | | 16 | lnk² | link^2, sq lnk, square link, square links | -| 17 | ac (US) | acre (US), acres (US) | +| 17 | us_ac | us acre, us acres | | 18 | ft² (US) | ft^2 (US), sq ft (US), square foot (US), square feet (US) | | 19 | mi² (US) | mi^2 (US), sq mi (US), square mile (US), square miles (US) | | 20 | ch² (US) | ch^2 (US), sq ch (US), square chain (US), square chains (US) | @@ -176,6 +176,9 @@ These units are defined in `UnitMeasurements::Area`. | 22 | dun | ḍn, dunam, dunams | | 23 | sec | sect, section, sections | | 24 | twp | survey township, survey townships | +| 25 | sq_ft | us square foot, us square feet | +| 26 | sq_mi | us square mile, us square miles | +| 27 | sq_ch | us square chain, us square chains | ## 9. Volume & capacity @@ -700,7 +703,7 @@ These units are defined in `UnitMeasurements::Power`. |:--|:--|:--| | _1_ | _W*_ | _watt, watts_ | | 2 | p | poncelet, poncelets | -| 3 | hp (M) | PS, metric horsepower | +| 3 | metric_hp | PS, metric horsepower | | 4 | kgf⋅m | kgf*m, kilogramme-force meter, kilogram-force meter | | 5 | cal/s | calorie per second, calories per second | | 6 | cal/min | calorie per minute, calories per minute |