-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue335-Unit-format-if-numerator-is-1-in-unit-faction (#348)
- Loading branch information
Showing
7 changed files
with
117 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
ruby-units (4.0.3) | ||
ruby-units (4.1.0) | ||
|
||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module RubyUnits | ||
class Unit < Numeric | ||
VERSION = '4.0.3'.freeze | ||
VERSION = '4.1.0'.freeze | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,52 @@ | ||
require 'spec_helper' | ||
|
||
describe RubyUnits::Configuration do | ||
describe '.separator is true' do | ||
it 'has a space between the scalar and the unit' do | ||
expect(RubyUnits::Unit.new('1 m').to_s).to eq '1 m' | ||
describe '.separator' do | ||
context 'when set to true' do | ||
it 'has a space between the scalar and the unit' do | ||
expect(RubyUnits::Unit.new('1 m').to_s).to eq '1 m' | ||
end | ||
end | ||
|
||
context 'when set to false' do | ||
around do |example| | ||
RubyUnits.configure do |config| | ||
config.separator = false | ||
end | ||
example.run | ||
RubyUnits.reset | ||
end | ||
|
||
it 'does not have a space between the scalar and the unit' do | ||
expect(RubyUnits::Unit.new('1 m').to_s).to eq '1m' | ||
expect(RubyUnits::Unit.new('14.5 lbs').to_s(:lbs)).to eq '14lbs 8oz' | ||
expect(RubyUnits::Unit.new('220 lbs').to_s(:stone)).to eq '15stone 10lbs' | ||
expect(RubyUnits::Unit.new('14.2 ft').to_s(:ft)).to eq %(14'2-2/5") | ||
expect(RubyUnits::Unit.new('1/2 cup').to_s).to eq '1/2cu' | ||
expect(RubyUnits::Unit.new('123.55 lbs').to_s('%0.2f')).to eq '123.55lbs' | ||
end | ||
end | ||
end | ||
|
||
describe '.separator is false' do | ||
around do |example| | ||
RubyUnits.configure do |config| | ||
config.separator = false | ||
describe '.format' do | ||
context 'when set to :rational' do | ||
it 'uses rational notation' do | ||
expect(RubyUnits::Unit.new('1 m/s^2').to_s).to eq '1 m/s^2' | ||
end | ||
example.run | ||
RubyUnits.reset | ||
end | ||
|
||
it 'does not have a space between the scalar and the unit' do | ||
expect(RubyUnits::Unit.new('1 m').to_s).to eq '1m' | ||
expect(RubyUnits::Unit.new('14.5 lbs').to_s(:lbs)).to eq '14lbs 8oz' | ||
expect(RubyUnits::Unit.new('220 lbs').to_s(:stone)).to eq '15stone 10lbs' | ||
expect(RubyUnits::Unit.new('14.2 ft').to_s(:ft)).to eq %(14'2-2/5") | ||
expect(RubyUnits::Unit.new('1/2 cup').to_s).to eq '1/2cu' | ||
expect(RubyUnits::Unit.new('123.55 lbs').to_s('%0.2f')).to eq '123.55lbs' | ||
context 'when set to :exponential' do | ||
around do |example| | ||
RubyUnits.configure do |config| | ||
config.format = :exponential | ||
end | ||
example.run | ||
RubyUnits.reset | ||
end | ||
|
||
it 'uses exponential notation' do | ||
expect(RubyUnits::Unit.new('1 m/s^2').to_s).to eq '1 m*s^-2' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters