ruby-units 2.3.0 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -1,27 +1,6 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'rake/testtask'
4
- require './lib/ruby-units'
5
-
6
- begin
7
- require 'jeweler'
8
- Jeweler::Tasks.new do |gem|
9
- gem.name = 'ruby-units'
10
- gem.summary = 'A class that performs unit conversions and unit math'
11
- gem.description = 'Provides classes and methods to perform unit math and conversions'
12
- gem.authors = ['Kevin Olbrich, Ph.D.']
13
- gem.email = ['kevin.olbrich+ruby_units@gmail.com']
14
- gem.homepage = 'https://github.com/olbrich/ruby-units'
15
- gem.files.exclude('.*', 'test/**/*', 'spec/**/*', 'Gemfile', 'Guardfile')
16
- gem.license = 'MIT'
17
- end
18
- Jeweler::GemcutterTasks.new
19
- rescue LoadError
20
- puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler'
21
- end
22
-
1
+ require 'bundler/gem_tasks'
23
2
  require 'rspec/core/rake_task'
24
- desc 'Run specs'
25
- RSpec::Core::RakeTask.new
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
26
5
 
27
6
  task default: :spec
data/lib/ruby-units.rb CHANGED
@@ -1,3 +1,2 @@
1
- $LOAD_PATH << File.dirname(__FILE__)
2
1
  require_relative 'ruby_units/namespaced'
3
2
  Unit = RubyUnits::Unit
@@ -24,9 +24,9 @@ module RubyUnits
24
24
 
25
25
  # holds actual configuration values for RubyUnits
26
26
  class Configuration
27
- # used to separate the scalar from the unit when generating output.
28
- # set to nil to prevent adding a space to the string representation of a unit
29
- # separators other than ' ' and '' may work, but you may encounter problems
27
+ # Used to separate the scalar from the unit when generating output. A value
28
+ # of `true` will insert a single space, and `false` will prevent adding a
29
+ # space to the string representation of a unit.
30
30
  attr_reader :separator
31
31
 
32
32
  def initialize
@@ -34,7 +34,8 @@ module RubyUnits
34
34
  end
35
35
 
36
36
  def separator=(value)
37
- raise ArgumentError, "configuration 'separator' may only be true or false" unless value.class == TrueClass || value.class == FalseClass
37
+ raise ArgumentError, "configuration 'separator' may only be true or false" unless value == true || value == false
38
+
38
39
  @separator = value ? ' ' : nil
39
40
  end
40
41
  end
@@ -16,6 +16,10 @@ class RubyUnits::Unit < Numeric
16
16
  # @return [Array]
17
17
  attr_accessor :denominator
18
18
 
19
+ # Unit name to be used when generating output. This MUST be a parseable
20
+ # string or it won't be possible to round trip the unit to a String and
21
+ # back.
22
+ #
19
23
  # @return [String]
20
24
  attr_accessor :display_name
21
25
 
@@ -48,7 +52,7 @@ class RubyUnits::Unit < Numeric
48
52
  end
49
53
 
50
54
  # set the name, strip off '<' and '>'
51
- # @param [String]
55
+ # @param name_value [String]
52
56
  # @return [String]
53
57
  def name=(name_value)
54
58
  @name = name_value.gsub(/[<>]/, '')
@@ -57,7 +61,7 @@ class RubyUnits::Unit < Numeric
57
61
  # alias array must contain the name of the unit and entries must be unique
58
62
  # @return [Array]
59
63
  def aliases
60
- [[@aliases], @name].flatten.compact.uniq
64
+ [[@aliases], @name, @display_name].flatten.compact.uniq
61
65
  end
62
66
 
63
67
  # define a unit in terms of another unit
@@ -1,6 +1,3 @@
1
-
2
- $LOAD_PATH << File.dirname(__FILE__)
3
-
4
1
  # require_relative this file to avoid creating an class alias from Unit to RubyUnits::Unit
5
2
  require_relative 'version'
6
3
  require_relative 'configuration'