Skip to content

Commit

Permalink
Merge pull request #73 from shivam091/5.19.0
Browse files Browse the repository at this point in the history
5.19.0
  • Loading branch information
shivam091 authored Jan 12, 2025
2 parents 19d3f2f + 091fc60 commit 1faac75
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 29 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
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.18.0)
unit_measurements (5.19.0)
activesupport (~> 7.0)

GEM
Expand Down
8 changes: 8 additions & 0 deletions lib/unit_measurements/unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/unit_measurements/unit_group_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
6 changes: 5 additions & 1 deletion lib/unit_measurements/unit_groups/area.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/unit_measurements/unit_groups/length.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/unit_measurements/unit_groups/power.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
4 changes: 2 additions & 2 deletions lib/unit_measurements/unit_groups/weight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.18.0"
VERSION = "5.19.0"
end
16 changes: 14 additions & 2 deletions spec/unit_measurements/unit_groups/area_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
8 changes: 4 additions & 4 deletions spec/unit_measurements/unit_groups/length_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/unit_measurements/unit_groups/power_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/unit_measurements/unit_groups/weight_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 10 additions & 7 deletions units.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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 |
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -168,14 +168,17 @@ 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) |
| 21 | Aₚ | planck area, quantum 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

Expand Down Expand Up @@ -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 |
Expand Down

0 comments on commit 1faac75

Please sign in to comment.