Skip to content

Commit

Permalink
Merge pull request #57 from shivam091/5.7.0
Browse files Browse the repository at this point in the history
5.7.0
  • Loading branch information
shivam091 authored Nov 4, 2023
2 parents 31b6a40 + 3dd1788 commit 11dbd69
Show file tree
Hide file tree
Showing 15 changed files with 276 additions and 84 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
## [5.7.0](https://github.com/shivam091/unit_measurements/compare/v5.6.1...v5.7.0) - 2023-11-04

### What's new

- Added new units `λ`, `cd`, and `cd-ft` in `volume`.
- Added new units `tn`, `LT`, `hyl`, `cwt`, and `cwt (US)` in `weight`.
- Added new units `μ`, `cb`, `b.c.`, `S`, `ls`, `lmin`, `lh`, `ld`, `lw`, `lm`, `ly` in `length`.
- Added new units `tr`, `cyc`, `sign`, `octant`, `sextant`, and `quadrant` in `plane angle`.

### What's removed

- Removed wrong plural aliases from units of `frequency` and `magnetic induction`.

----------

## [5.6.1](https://github.com/shivam091/unit_measurements/compare/v5.6.0...v5.6.1) - 2023-11-03

### What's removed
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.6.1)
unit_measurements (5.7.0)
activesupport (~> 7.0)

GEM
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ UnitMeasurements::Length.new(17.625, "m").round
You can check supported mathematical functions along with their examples
[here](https://shivam091.github.io/unit_measurements/UnitMeasurements/Math.html).

### Conversions
### Numeric conversions

You can convert measurement quantity directly to other numeric types viz.
`Integer`, `BigDecimal`, `Rational`, `Complex`, and `Float`.
Expand Down
2 changes: 1 addition & 1 deletion lib/unit_measurements/unit_groups/frequency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
primitive "Hz"

system :metric do
si_unit "Hz", aliases: ["hertz", "hertzes"]
si_unit "Hz", aliases: ["hertz"]

unit "deg/s", value: [Rational(1, 360), "Hz"], aliases: ["°/s", "degree per second", "degrees per second"]
unit "rad/s", value: [Rational(1, (2 * Math::PI)), "Hz"], aliases: ["radian per second", "radians per second"]
Expand Down
20 changes: 19 additions & 1 deletion lib/unit_measurements/unit_groups/length.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
si_unit "m", aliases: ["meter", "metre", "meters", "metres"]

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)"]
end

system :imperial do
Expand All @@ -21,21 +24,36 @@
unit "ch", value: "22 yd", aliases: ["chain", "chains"]
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 "ftm", value: "6 ft", aliases: ["fathom", "fathoms"]
unit "fur", value: "220 yd", aliases: ["furlong", "furlongs"]
unit "nmi", value: "1852 m", aliases: ["NMI", "M", "NM", "nautical mile", "nautical miles"]
unit "rod", value: "16 1/2 ft", aliases: ["rods", "perch", "pole", "lug"]
unit "lnk", value: "33/50 ft", aliases: ["l", "li", "link", "links"]
unit "lea", value: "3 mi", aliases: ["league", "leagues"]

unit "b.c.", value: "1/3 in", aliases: ["bc", "barleycorn", "barleycorns"]
end

system :us_customary do
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)"]
end

system :astronomical do
unit "S", value: "1e+9 km", aliases: ["spat", "spats"]

unit "au", value: "149597870700 m", aliases: ["astronomical unit", "astronomical units"]
unit "pc", value: [Rational(648000, Math::PI), "au"], aliases: ["parsec", "parsecs"]

unit "ls", value: "299792458 m", aliases: ["light-second", "light-seconds"]
unit "lmin", value: "60 ls", aliases: ["light-minute", "light-minutes"]
unit "lh", value: "60 lmin", aliases: ["light-hour", "light-hours"]
unit "ld", value: "24 lh", aliases: ["light-day", "light-days"]
unit "lw", value: "7 ld", aliases: ["light-week", "light-weeks"]
unit "lm", value: "30 ld", aliases: ["light-month", "light-months"]
unit "ly", value: "365.25 ld", aliases: ["light-year", "light-years"]
end
end
2 changes: 1 addition & 1 deletion lib/unit_measurements/unit_groups/magnetic_induction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
end

system :centimetre_gram_second do
unit "G", value: "1e-4 T", aliases: ["Gs", "gauss", "gausses"]
unit "G", value: "1e-4 T", aliases: ["Gs", "gauss"]
end
end
24 changes: 16 additions & 8 deletions lib/unit_measurements/unit_groups/plane_angle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@
system :metric do
si_unit "rad", aliases: ["radian", "radians"]

unit "deg", value: [(Math::PI / 180), "rad"], aliases: ["°", "degree", "degrees"] # (π / 180) rad
unit "gon", value: [(Math::PI / 200), "rad"], aliases: ["ᵍ", "grad", "gradian", "gradians"] # (π / 200) rad
unit "arcmin", value: [Rational(1, 60), "deg"], aliases: ["′", "amin", "arcminute", "arcminutes"] # ((π / 180) / 60) rad
unit "arcsec", value: [Rational(1, 60), "arcmin"], aliases: ["″", "asec", "arcsecond", "arcseconds"] # ((π / 180) / 3600) rad
unit "deg", value: [(Math::PI / 180), "rad"], aliases: ["°", "degree", "degrees", "degree of arc", "degrees of arc", "arcdegree", "arcdegrees"]
unit "gon", value: [(Math::PI / 200), "rad"], aliases: ["ᵍ", "grad", "gradian", "gradians"]
unit "arcmin", value: [Rational(1, 60), "deg"], aliases: ["′", "amin", "arcminute", "arcminutes"]
unit "arcsec", value: [Rational(1, 60), "arcmin"], aliases: ["″", "asec", "arcsecond", "arcseconds"]
end

unit "cir", value: [360, "deg"], aliases: ["circle", "circles"] # (2 * π) rad
unit "mil", value: [Rational(1, 6400), "cir"], aliases: ["mils"] # ((2 * π) / 6400) rad
unit "rev", value: [1, "cir"], aliases: ["revolution", "revolutions"] # (2 * π) rad
unit "tr", value: [1, "cir"], aliases: ["turn", "turns"]

unit "brad", value: [(Math::PI / 128), "rad"], aliases: ["b°", "bdeg", "binary degree", "binary radian", "binary degrees", "binary radians"] # (π / 128) rad
unit "cir", value: [360, "deg"], aliases: ["circle", "circles"]
unit "rev", value: [1, "cir"], aliases: ["revolution", "revolutions"]
unit "cyc", value: [1, "cir"], aliases: ["cycle", "cycles"]
unit "mil", value: [Rational(1, 6400), "cir"], aliases: ["mils"]

unit "brad", value: [(Math::PI / 128), "rad"], aliases: ["b°", "bdeg", "binary degree", "binary radian", "binary degrees", "binary radians"]

unit "sign", value: "30 deg", aliases: ["signs"]
unit "octant", value: "45 deg", aliases: ["octants"]
unit "sextant", value: "60 deg", aliases: ["sextants"]
unit "quadrant", value: "90 deg", aliases: ["quadrants"]
end
7 changes: 6 additions & 1 deletion lib/unit_measurements/unit_groups/volume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
system :metric do
si_unit "l", aliases: ["liter", "litre", "liters", "litres"]

unit "λ", value: "1e-9 m³", aliases: ["lambda", "lambdas"]
unit "m³", value: "1000 l", aliases: ["m^3", "cu m", "cubic meter", "cubic meters", "cubic metre", "cubic metres"]

unit "mm³", value: "1e-9 m³", aliases: ["mm^3", "cu mm", "cubic millimeter", "cubic millimeters", "cubic millimetre", "cubic millimetres"]
Expand Down Expand Up @@ -40,16 +41,20 @@
unit "hhd", value: "2 bbl", aliases: ["hogshead", "hogsheads"]
unit "fls", value: "1/24 floz", aliases: ["fluid scruple", "fluid scruples"]

unit "dspn", value: "10 ml", aliases: ["dsp", "dessertspoon", "dessertspoons"]
unit "dspn", value: "10 ml", aliases: ["dsp", "dstspn", "dessertspoon", "dessertspoons"]
unit "tbsp", value: "3 tsp", aliases: ["tbs", "tablespoon", "tablespoons"]
unit "floz", value: "1/160 gal", aliases: ["fluid ounce", "fluid ounces"]
unit "fldr", value: "1/8 floz", aliases: ["fluid drachm", "fluid drachms"]
end

system :us_customary do
unit "cd", value: "128 ft³", aliases: ["cord", "cords"]

unit "bdft", value: "144 in³", aliases: ["bf", "fbm", "board-foot", "board-feet"]

unit "ac⋅ft", value: "43560 ft³", aliases: ["acre-foot", "acre-feet"]
unit "ac⋅in", value: "6272640 in³", aliases: ["acre-inch", "acre-inches"]

unit "cd-ft", value: "1/8 cd", aliases: ["cord-foot", "cord-feet"]
end
end
11 changes: 11 additions & 0 deletions lib/unit_measurements/unit_groups/weight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,22 @@
unit "oz", value: "1/16 lb", aliases: ["ounce", "ounces"]
unit "dr", value: "1/16 oz", aliases: ["dram", "drams"]
unit "gr", value: "1/7000 lb", aliases: ["grain", "grains"]
unit "LT", value: "2240 lb", aliases: ["imperial ton", "displacement ton", "imperial tons", "displacement tons", "long ton", "long tons", "weight ton", "weight tons"]

unit "drt", value: "60 gr", aliases: ["troy dram", "troy drams"]
unit "ozt", value: "480 gr", aliases: ["troy ounce", "troy ounces"]
unit "lbt", value: "5760 gr", aliases: ["troy pound", "troy pounds"]
unit "dwt", value: "1/20 ozt", aliases: ["pwt", "pennyweight", "pennyweights"]
unit "cwt", value: "112 lb", aliases: ["hundredweight", "long hundredweight", "imperial hundredweight"]
end

system :us_customary do
unit "tn", value: "2000 lb", aliases: ["ton", "tons", "short ton", "short tons"]
unit "cwt (US)", value: "100 lb", aliases: ["hundredweight (US)", "short hundredweight"]
end

system :gravitational_metric do
unit "hyl", value: "9.80665 kg", aliases: ["mug", "metric slug", "metric slugs", "hyls"]
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.6.1"
VERSION = "5.7.0"
end
60 changes: 56 additions & 4 deletions spec/unit_measurements/unit_groups/length_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
expect(subject.convert_to("h").quantity).to eq(49.2125984251969)
end

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

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

it "converts to in" do
expect(subject.convert_to("in").quantity).to eq(196.850393700787)
end
Expand Down Expand Up @@ -52,6 +60,38 @@
expect(subject.convert_to("nl").quantity).to eq(0.000899928005759539)
end

it "converts to rd" do
expect(subject.convert_to("rd").quantity).to eq(0.994193907579734)
end

it "converts to ls" do
expect(subject.convert_to("ls").quantity).to eq(1.66782047599076e-8)
end

it "converts to lh" do
expect(subject.convert_to("lh").quantity).to eq(4.63283465552989e-12)
end

it "converts to ld" do
expect(subject.convert_to("ld").quantity).to eq(1.93034777313745e-13)
end

it "converts to lw" do
expect(subject.convert_to("lw").quantity).to eq(2.75763967591065e-14)
end

it "converts to lm" do
expect(subject.convert_to("lm").quantity).to eq(6.43449257712485e-15)
end

it "converts to ly" do
expect(subject.convert_to("ly").quantity).to eq(5.28500417012308e-16)
end

it "converts to cb" do
expect(subject.convert_to("cb").quantity).to eq(0.0269805912418842)
end

it "converts to ftm" do
expect(subject.convert_to("ftm").quantity).to eq(2.73403324584427)
end
Expand All @@ -64,10 +104,6 @@
expect(subject.convert_to("nmi").quantity).to eq(0.00269978401727862)
end

it "converts to rod" do
expect(subject.convert_to("rod").quantity).to eq(0.994193907579734)
end

it "converts to lnk" do
expect(subject.convert_to("lnk").quantity).to eq(24.8548476894934)
end
Expand All @@ -79,5 +115,21 @@
it "converts to sft" do
expect(subject.convert_to("sft").quantity).to eq(16.4041666666667)
end

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

it "converts to b.c." do
expect(subject.convert_to("b.c.").quantity).to eq(590.551181102362)
end

it "converts to cb (M)" do
expect(subject.convert_to("cb (M)").quantity).to eq(0.0269978401727862)
end

it "converts to cb (US)" do
expect(subject.convert_to("cb (US)").quantity).to eq(0.0227836103820356)
end
end
end
24 changes: 24 additions & 0 deletions spec/unit_measurements/unit_groups/plane_angle_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
describe "rad" do
subject { described_class.new(5, "rad") }

it "converts to tr" do
expect(subject.convert_to("tr").quantity).to eq(0.795774715459477)
end

it "converts to deg" do
expect(subject.convert_to("deg").quantity).to eq(286.478897565412)
end
Expand All @@ -16,6 +20,10 @@
expect(subject.convert_to("gon").quantity).to eq(318.309886183791)
end

it "converts to cyc" do
expect(subject.convert_to("cyc").quantity).to eq(0.795774715459477)
end

it "converts to cir" do
expect(subject.convert_to("cir").quantity).to eq(0.795774715459477)
end
Expand All @@ -32,12 +40,28 @@
expect(subject.convert_to("brad").quantity).to eq(203.718327157626)
end

it "converts to sign" do
expect(subject.convert_to("sign").quantity).to eq(9.54929658551372)
end

it "converts to arcmin" do
expect(subject.convert_to("arcmin").quantity).to eq(17188.7338539247)
end

it "converts to arcsec" do
expect(subject.convert_to("arcsec").quantity).to eq(1.03132403123548e+6)
end

it "converts to octant" do
expect(subject.convert_to("octant").quantity).to eq(6.36619772367581)
end

it "converts to sextant" do
expect(subject.convert_to("sextant").quantity).to eq(4.77464829275686)
end

it "converts to quadrant" do
expect(subject.convert_to("quadrant").quantity).to eq(3.18309886183791)
end
end
end
12 changes: 12 additions & 0 deletions spec/unit_measurements/unit_groups/volume_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
expect(subject.convert_to("l").quantity).to eq(5000)
end

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

it "converts to mm³" do
expect(subject.convert_to("mm³").quantity).to eq(5e+9)
end
Expand Down Expand Up @@ -72,6 +76,10 @@
expect(subject.convert_to("gt").quantity).to eq(5.06809148081098e+7)
end

it "converts to cd" do
expect(subject.convert_to("cd").quantity).to eq(1.37947916880815)
end

it "converts to gal" do
expect(subject.convert_to("gal").quantity).to eq(1099.84624149544)
end
Expand Down Expand Up @@ -131,5 +139,9 @@
it "converts to ac⋅in" do
expect(subject.convert_to("ac⋅in").quantity).to eq(0.0486427916273948)
end

it "converts to cd-ft" do
expect(subject.convert_to("cd-ft").quantity).to eq(11.0358333504652)
end
end
end
20 changes: 20 additions & 0 deletions spec/unit_measurements/unit_groups/weight_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
expect(subject.convert_to("dr").quantity).to eq(2.82191695596643)
end

it "converts to tn" do
expect(subject.convert_to("tn").quantity).to eq(5.51155655462194e-6)
end

it "converts to LT" do
expect(subject.convert_to("LT").quantity).to eq(4.9210326380553e-6)
end

it "converts to ozt" do
expect(subject.convert_to("ozt").quantity).to eq(0.16075373284314)
end
Expand All @@ -68,8 +76,20 @@
expect(subject.convert_to("lbt").quantity).to eq(0.013396144403595)
end

it "converts to hyl" do
expect(subject.convert_to("hyl").quantity).to eq(0.000509858106488964)
end

it "converts to cwt" do
expect(subject.convert_to("cwt").quantity).to eq(0.0000984206527611061)
end

it "converts to slug" do
expect(subject.convert_to("slug").quantity).to eq(0.000342608829245948)
end

it "converts to cwt (US)" do
expect(subject.convert_to("cwt (US)").quantity).to eq(0.000110231131092439)
end
end
end
Loading

0 comments on commit 11dbd69

Please sign in to comment.