Skip to content

Commit

Permalink
Maintenance (#160)
Browse files Browse the repository at this point in the history
* update supported ruby versions, install rubocop
  • Loading branch information
olbrich committed Oct 1, 2017
1 parent ae87805 commit 73a9893
Show file tree
Hide file tree
Showing 14 changed files with 198 additions and 203 deletions.
9 changes: 1 addition & 8 deletions .codeclimate.yml
Expand Up @@ -15,16 +15,9 @@ engines:
enabled: true
rubocop:
enabled: true
channel: rubocop-0-49
ratings:
paths:
- Gemfile.lock
- "**.css"
- "**.inc"
- "**.js"
- "**.jsx"
- "**.module"
- "**.php"
- "**.py"
- "**.rb"
exclude_paths:
- ruby-units.gemspec
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
@@ -1 +1 @@
2.4.1
2.2.8
8 changes: 4 additions & 4 deletions .travis.yml
@@ -1,10 +1,10 @@
sudo: false
language: ruby
rvm:
- 2.4.1
- 2.3.4
- 2.2.7
- 2.4.2
- 2.3.5
- 2.2.8
- ruby-head
- jruby-9.1.6.0
- jruby-9.1.13.0
script: bundle exec rake --trace
bundler_args: --without development
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -14,6 +14,7 @@ end
group :test do
gem 'rake'
gem 'rspec'
gem 'rubocop', '= 0.49.1' # match codeclimate
gem 'simplecov'
gem 'simplecov-html'
end
2 changes: 1 addition & 1 deletion Guardfile
Expand Up @@ -2,7 +2,7 @@
# More info at https://github.com/guard/guard#readme

## Uncomment and set this to only include directories you want to watch
directories %w(lib spec)
directories %w[lib spec]

## Uncomment to clear the screen before every task
clearing :on
Expand Down
4 changes: 2 additions & 2 deletions lib/ruby_units/date.rb
Expand Up @@ -9,7 +9,7 @@ class Date
def +(other)
case other
when RubyUnits::Unit
other = other.convert_to('d').round if %w(y decade century).include? other.units
other = other.convert_to('d').round if %w[y decade century].include? other.units
unit_date_add(other.convert_to('day').scalar)
else
unit_date_add(other)
Expand All @@ -22,7 +22,7 @@ def +(other)
def -(other)
case other
when RubyUnits::Unit
other = other.convert_to('d').round if %w(y decade century).include? other.units
other = other.convert_to('d').round if %w[y decade century].include? other.units
unit_date_sub(other.convert_to('day').scalar)
else
unit_date_sub(other)
Expand Down
4 changes: 2 additions & 2 deletions lib/ruby_units/time.rb
Expand Up @@ -45,7 +45,7 @@ def to_unit(other = nil)
def +(other)
case other
when RubyUnits::Unit
other = other.convert_to('d').round.convert_to('s') if %w(y decade century).include? other.units
other = other.convert_to('d').round.convert_to('s') if %w[y decade century].include? other.units
begin
unit_add(other.convert_to('s').scalar)
rescue RangeError
Expand All @@ -69,7 +69,7 @@ def self.in(duration)
def -(other)
case other
when RubyUnits::Unit
other = other.convert_to('d').round.convert_to('s') if %w(y decade century).include? other.units
other = other.convert_to('d').round.convert_to('s') if %w[y decade century].include? other.units
begin
unit_sub(other.convert_to('s').scalar)
rescue RangeError
Expand Down
7 changes: 4 additions & 3 deletions lib/ruby_units/unit.rb
@@ -1,4 +1,5 @@
# encoding: utf-8

require 'date'
# Copyright 2006-2015
# @author Kevin C. Olbrich, Ph.D.
Expand Down Expand Up @@ -62,7 +63,7 @@ class Unit < Numeric
RANKINE = ['<rankine>'].freeze
CELSIUS = ['<celsius>'].freeze
@@temp_regex = nil
SIGNATURE_VECTOR = %i(
SIGNATURE_VECTOR = %i[
length
time
temperature
Expand All @@ -73,7 +74,7 @@ class Unit < Numeric
currency
information
angle
).freeze
].freeze
@@kinds = {
-312_078 => :elastance,
-312_058 => :resistance,
Expand Down Expand Up @@ -369,7 +370,7 @@ def self.prefix_regex

def self.temp_regex
@@temp_regex ||= begin
temp_units = %w(tempK tempC tempF tempR degK degC degF degR)
temp_units = %w[tempK tempC tempF tempR degK degC degF degR]
aliases = temp_units.map do |unit|
d = RubyUnits::Unit.definition(unit)
d && d.aliases
Expand Down
56 changes: 28 additions & 28 deletions lib/ruby_units/unit_definitions/base.rb
Expand Up @@ -3,98 +3,98 @@

RubyUnits::Unit.define('meter') do |unit|
unit.scalar = 1
unit.numerator = %w(<meter>)
unit.aliases = %w(m meter meters metre metres)
unit.numerator = %w[<meter>]
unit.aliases = %w[m meter meters metre metres]
unit.kind = :length
end

RubyUnits::Unit.define('kilogram') do |unit|
unit.scalar = 1
unit.numerator = %w(<kilogram>)
unit.aliases = %w(kg kilogram kilograms)
unit.numerator = %w[<kilogram>]
unit.aliases = %w[kg kilogram kilograms]
unit.kind = :mass
end

RubyUnits::Unit.define('second') do |unit|
unit.scalar = 1
unit.numerator = %w(<second>)
unit.aliases = %w(s sec second seconds)
unit.numerator = %w[<second>]
unit.aliases = %w[s sec second seconds]
unit.kind = :time
end

RubyUnits::Unit.define('mole') do |unit|
unit.scalar = 1
unit.numerator = %w(<mole>)
unit.aliases = %w(mol mole)
unit.numerator = %w[<mole>]
unit.aliases = %w[mol mole]
unit.kind = :substance
end

RubyUnits::Unit.define('ampere') do |unit|
unit.scalar = 1
unit.numerator = %w(<ampere>)
unit.aliases = %w(A ampere amperes amp amps)
unit.numerator = %w[<ampere>]
unit.aliases = %w[A ampere amperes amp amps]
unit.kind = :current
end

RubyUnits::Unit.define('radian') do |unit|
unit.scalar = 1
unit.numerator = %w(<radian>)
unit.aliases = %w(rad radian radians)
unit.numerator = %w[<radian>]
unit.aliases = %w[rad radian radians]
unit.kind = :angle
end

RubyUnits::Unit.define('kelvin') do |unit|
unit.scalar = 1
unit.numerator = %w(<kelvin>)
unit.aliases = %w(degK kelvin)
unit.numerator = %w[<kelvin>]
unit.aliases = %w[degK kelvin]
unit.kind = :temperature
end

RubyUnits::Unit.define('tempK') do |unit|
unit.scalar = 1
unit.numerator = %w(<tempK>)
unit.aliases = %w(tempK)
unit.numerator = %w[<tempK>]
unit.aliases = %w[tempK]
unit.kind = :temperature
end

RubyUnits::Unit.define('byte') do |unit|
unit.scalar = 1
unit.numerator = %w(<byte>)
unit.aliases = %w(B byte bytes)
unit.numerator = %w[<byte>]
unit.aliases = %w[B byte bytes]
unit.kind = :information
end

RubyUnits::Unit.define('dollar') do |unit|
unit.scalar = 1
unit.numerator = %w(<dollar>)
unit.aliases = %w(USD dollar)
unit.numerator = %w[<dollar>]
unit.aliases = %w[USD dollar]
unit.kind = :currency
end

RubyUnits::Unit.define('candela') do |unit|
unit.scalar = 1
unit.numerator = %w(<candela>)
unit.aliases = %w(cd candela)
unit.numerator = %w[<candela>]
unit.aliases = %w[cd candela]
unit.kind = :luminosity
end

RubyUnits::Unit.define('each') do |unit|
unit.scalar = 1
unit.numerator = %w(<each>)
unit.aliases = %w(each)
unit.numerator = %w[<each>]
unit.aliases = %w[each]
unit.kind = :counting
end

RubyUnits::Unit.define('steradian') do |unit|
unit.scalar = 1
unit.numerator = %w(<steradian>)
unit.aliases = %w(sr steradian steradians)
unit.numerator = %w[<steradian>]
unit.aliases = %w[sr steradian steradians]
unit.kind = :solid_angle
end

RubyUnits::Unit.define('decibel') do |unit|
unit.scalar = 1
unit.numerator = %w(<decibel>)
unit.aliases = %w(dB decibel decibels)
unit.numerator = %w[<decibel>]
unit.aliases = %w[dB decibel decibels]
unit.kind = :logarithmic
end
60 changes: 30 additions & 30 deletions lib/ruby_units/unit_definitions/prefix.rb
@@ -1,36 +1,36 @@
# encoding: utf-8

{
'googol' => [%w(googol), 1e100],
'yobi' => [%w(Yi Yobi yobi), 2**80],
'zebi' => [%w(Zi Zebi zebi), 2**70],
'exbi' => [%w(Ei Exbi exbi), 2**60],
'pebi' => [%w(Pi Pebi pebi), 2**50],
'tebi' => [%w(Ti Tebi tebi), 2**40],
'gibi' => [%w(Gi Gibi gibi), 2**30],
'mebi' => [%w(Mi Mebi mebi), 2**20],
'kibi' => [%w(Ki Kibi kibi), 2**10],
'yotta' => [%w(Y Yotta yotta), 1e24],
'zetta' => [%w(Z Zetta zetta), 1e21],
'exa' => [%w(E Exa exa), 1e18],
'peta' => [%w(P Peta peta), 1e15],
'tera' => [%w(T Tera tera), 1e12],
'giga' => [%w(G Giga giga), 1e9],
'mega' => [%w(M Mega mega), 1e6],
'kilo' => [%w(k kilo), 1e3],
'hecto' => [%w(h Hecto hecto), 1e2],
'deca' => [%w(da Deca deca deka), 1e1],
'1' => [%w(1), 1],
'deci' => [%w(d Deci deci), Rational(1, 1e1)],
'centi' => [%w(c Centi centi), Rational(1, 1e2)],
'milli' => [%w(m Milli milli), Rational(1, 1e3)],
'micro' => [%w(u µ Micro micro mc), Rational(1, 1e6)],
'nano' => [%w(n Nano nano), Rational(1, 1e9)],
'pico' => [%w(p Pico pico), Rational(1, 1e12)],
'femto' => [%w(f Femto femto), Rational(1, 1e15)],
'atto' => [%w(a Atto atto), Rational(1, 1e18)],
'zepto' => [%w(z Zepto zepto), Rational(1, 1e21)],
'yocto' => [%w(y Yocto yocto), Rational(1, 1e24)]
'googol' => [%w[googol], 1e100],
'yobi' => [%w[Yi Yobi yobi], 2**80],
'zebi' => [%w[Zi Zebi zebi], 2**70],
'exbi' => [%w[Ei Exbi exbi], 2**60],
'pebi' => [%w[Pi Pebi pebi], 2**50],
'tebi' => [%w[Ti Tebi tebi], 2**40],
'gibi' => [%w[Gi Gibi gibi], 2**30],
'mebi' => [%w[Mi Mebi mebi], 2**20],
'kibi' => [%w[Ki Kibi kibi], 2**10],
'yotta' => [%w[Y Yotta yotta], 1e24],
'zetta' => [%w[Z Zetta zetta], 1e21],
'exa' => [%w[E Exa exa], 1e18],
'peta' => [%w[P Peta peta], 1e15],
'tera' => [%w[T Tera tera], 1e12],
'giga' => [%w[G Giga giga], 1e9],
'mega' => [%w[M Mega mega], 1e6],
'kilo' => [%w[k kilo], 1e3],
'hecto' => [%w[h Hecto hecto], 1e2],
'deca' => [%w[da Deca deca deka], 1e1],
'1' => [%w[1], 1],
'deci' => [%w[d Deci deci], Rational(1, 1e1)],
'centi' => [%w[c Centi centi], Rational(1, 1e2)],
'milli' => [%w[m Milli milli], Rational(1, 1e3)],
'micro' => [%w[u µ Micro micro mc], Rational(1, 1e6)],
'nano' => [%w[n Nano nano], Rational(1, 1e9)],
'pico' => [%w[p Pico pico], Rational(1, 1e12)],
'femto' => [%w[f Femto femto], Rational(1, 1e15)],
'atto' => [%w[a Atto atto], Rational(1, 1e18)],
'zepto' => [%w[z Zepto zepto], Rational(1, 1e21)],
'yocto' => [%w[y Yocto yocto], Rational(1, 1e24)]
}.each do |name, definition|
RubyUnits::Unit.define(name) do |unit|
aliases, scalar = definition
Expand Down

0 comments on commit 73a9893

Please sign in to comment.