unitwise 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 856dafc49ff1ab7e67a413b4d624f967d54ab8e0
4
- data.tar.gz: a4960934e8a31ca2c7906f20c76af4b544dd6a69
3
+ metadata.gz: 3f269726294777e995dada36f1169f639de28b5f
4
+ data.tar.gz: e9bc9e48ee65a4d08539d5ee85c7cb2d14d65573
5
5
  SHA512:
6
- metadata.gz: a72d207aa8b7aff3f700e7645060566c23590857be3072ba63f59bf23b578caf10e8b5e7d1c23d4b9f2350c16a2b49ef8bc524d00ecf0333f3bbef526611d261
7
- data.tar.gz: 1c8f05c32997d78a957955f951737d5f65371f614af3b39dedf898faf50a55e281f5139e0f205af844d099c7c9d4e3232508ef7255ec6ea4c9e22252b6abfabc
6
+ metadata.gz: e5f8cd371aac1c89b4eeab25f3f5d92fa45029244073deb0515dd9ef4c5347d8b91a96838b71319ec040147fed46a0f4b91656296839c408230f9f823bf14860
7
+ data.tar.gz: 17cdcce509f3db09c4cb607f8d51c64d0ea5a6ae51653f0a8c56de61756f75d280f677ac6a06c3086058a6f83d8c121a570ef234c6d23be3788038b67a74496e
data/.travis.yml CHANGED
@@ -2,6 +2,9 @@ language: ruby
2
2
  cache: bundler
3
3
  bundler_args: --without yard pry
4
4
  rvm:
5
+ - ree
6
+ - 1.8.7
7
+ - 1.9.2
5
8
  - 1.9.3
6
9
  - 2.0.0
7
10
  - 2.1.0
@@ -9,6 +12,8 @@ rvm:
9
12
  - rbx-2
10
13
  matrix:
11
14
  include:
15
+ - rvm: jruby-18mode
16
+ env: JRUBY_OPTS="$JRUBY_OPTS --debug"
12
17
  - rvm: jruby-19mode
13
18
  env: JRUBY_OPTS="$JRUBY_OPTS --debug"
14
19
  - rvm: jruby-head
data/README.md CHANGED
@@ -90,8 +90,7 @@ compatible unit.
90
90
  ```
91
91
 
92
92
  The prettier version of `convert_to(unit)` is appending the unit code, name, etc.
93
- to a `to_` message.
94
- name.
93
+ to a `to_` message name.
95
94
 
96
95
  ```ruby
97
96
  Unitwise(26.2, 'mile').to_kilometer
@@ -198,7 +197,6 @@ Regexp.
198
197
  ```ruby
199
198
  Unitwise.search('fathom')
200
199
  # => [ ... ]
201
-
202
200
  ```
203
201
 
204
202
  You can also get the official list from the UCUM website in XML format at
@@ -211,11 +209,14 @@ or a YAML version within this repo
211
209
  This library aims to support and is tested against the following Ruby
212
210
  implementations:
213
211
 
212
+ * Ruby 1.8.7
213
+ * Ruby 1.9.2
214
214
  * Ruby 1.9.3
215
215
  * Ruby 2.0.0
216
216
  * Ruby 2.1.0
217
217
  * [JRuby](http://jruby.org/)
218
218
  * [Rubinius](http://rubini.us/)
219
+ * [Ruby Enterprise Edition](http://www.rubyenterpriseedition.com/)
219
220
 
220
221
  If something doesn't work on one of these versions, it's a bug.
221
222
 
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ Rake::TestTask.new do |t|
7
7
  t.pattern = 'test/**/*_test.rb'
8
8
  end
9
9
 
10
- task default: :test
10
+ task :default => :test
11
11
 
12
12
  namespace :unitwise do
13
13
  desc "Update Ucum Data"
data/lib/unitwise/atom.rb CHANGED
@@ -102,26 +102,19 @@ module Unitwise
102
102
  # or operate on. Base units have a scalar of 1.
103
103
  # @return [Numeric]
104
104
  # @api public
105
- def scalar(x = 1)
106
- base? ? 1 : scale.scalar(x)
105
+ def scalar(magnitude = 1)
106
+ base? ? magnitude : scale.scalar(magnitude)
107
107
  end
108
108
 
109
- def inverse_scalar(x = 1)
110
- base? ? 1 : scale.inverse_scalar(x)
109
+ def magnitude(scalar = scalar)
110
+ special? ? scale.magnitude(scalar) : 1
111
111
  end
112
112
 
113
- # Get a functional value that can be used with other atoms to compare with
114
- # or operate on.
115
- # @param x [Numeric] The number to convert to or convert from
116
- # @param forward [true, false] Convert to or convert from
117
- # @return [Numeric] The converted value
118
-
119
-
120
113
  # An atom may have a complex scale with several base atoms at various
121
114
  # depths. This method returns all of this atoms base level terms.
122
115
  # @return [Array] An array containing base Unitwise::Term
123
116
  def root_terms
124
- base? ? [Term.new(atom_code: primary_code)] : scale.root_terms
117
+ base? ? [Term.new(:atom_code => primary_code)] : scale.root_terms
125
118
  end
126
119
  end
127
120
  end
data/lib/unitwise/base.rb CHANGED
@@ -22,7 +22,7 @@ module Unitwise
22
22
  def self.find(string, method = :primary_code)
23
23
  all.find do |i|
24
24
  key = i.send(method)
25
- if key.respond_to?(:each)
25
+ if key.is_a? Array
26
26
  key.include?(string)
27
27
  else
28
28
  key == string
@@ -8,7 +8,7 @@ module Unitwise
8
8
 
9
9
  def set
10
10
  @set ||= terms.reduce(SignedMultiset.new) do |s, t|
11
- s.increment({f: t.factor, p: t.prefix, a: t.atom}, t.exponent); s
11
+ s.increment({:f => t.factor, :p => t.prefix, :a => t.atom}, t.exponent); s
12
12
  end
13
13
  end
14
14
 
@@ -22,7 +22,7 @@ module Unitwise
22
22
  def transform
23
23
  PARSERS.reduce(nil) do |foo, (method, parser)|
24
24
  if parsed = parser.parse(expression) rescue next
25
- return TRANSFORMER.apply(parsed, key: method)
25
+ return TRANSFORMER.apply(parsed, :key => method)
26
26
  end
27
27
  end
28
28
  end
@@ -38,4 +38,4 @@ module Unitwise
38
38
 
39
39
  end
40
40
  end
41
- end
41
+ end
@@ -2,29 +2,29 @@ module Unitwise
2
2
  module Expression
3
3
  class Transformer < Parslet::Transform
4
4
 
5
- rule(integer: simple(:i)) { i.to_i }
6
- rule(fixnum: simple(:f)) { f.to_f }
5
+ rule(:integer => simple(:i)) { i.to_i }
6
+ rule(:fixnum => simple(:f)) { f.to_f }
7
7
 
8
- rule(prefix_code: simple(:c)) { |ctx| Prefix.find(ctx[:c], ctx[:key]) }
9
- rule(atom_code: simple(:c)) { |ctx| Atom.find(ctx[:c], ctx[:key]) }
10
- rule(term: subtree(:h)) { Term.new(h) }
8
+ rule(:prefix_code => simple(:c)) { |ctx| Prefix.find(ctx[:c], ctx[:key]) }
9
+ rule(:atom_code => simple(:c)) { |ctx| Atom.find(ctx[:c], ctx[:key]) }
10
+ rule(:term => subtree(:h)) { Term.new(h) }
11
11
 
12
- rule(operator: simple(:o), right: simple(:r)) do
12
+ rule(:operator => simple(:o), :right => simple(:r)) do
13
13
  o == '/' ? r ** -1 : r
14
14
  end
15
15
 
16
- rule(left: simple(:l), operator: simple(:o), right: simple(:r)) do
16
+ rule(:left => simple(:l), :operator => simple(:o), :right => simple(:r)) do
17
17
  o == '/' ? l / r : l * r
18
18
  end
19
19
 
20
- rule(left: simple(:l)) { l }
20
+ rule(:left => simple(:l)) { l }
21
21
 
22
- rule(group: { factor: simple(:f) , nested: simple(:n), exponent: simple(:e) }) do
22
+ rule(:group => { :factor => simple(:f) , :nested => simple(:n), :exponent => simple(:e) }) do
23
23
  ( n ** e ) * f
24
24
  end
25
- rule(group: { nested: simple(:n) , exponent: simple(:e)}) { n ** e }
25
+ rule(:group => { :nested => simple(:n) , :exponent => simple(:e)}) { n ** e }
26
26
 
27
- rule(group: { nested: simple(:n) }) { n }
27
+ rule(:group => { :nested => simple(:n) }) { n }
28
28
  end
29
29
  end
30
30
  end
@@ -16,7 +16,7 @@ class Numeric
16
16
  # @api semipublic
17
17
  def method_missing(meth, *args, &block)
18
18
  if args.empty? && !block_given?
19
- unit = (match = /\Ato_(\w+)\Z/.match(meth)) ? match[1] : meth
19
+ unit = (match = /\Ato_(\w+)\Z/.match(meth.to_s)) ? match[1] : meth
20
20
  begin
21
21
  convert_to(unit)
22
22
  rescue Unitwise::ExpressionError
@@ -49,13 +49,13 @@ module Unitwise
49
49
  def self.to_ph(x)
50
50
  to_hpX(x)
51
51
  end
52
-
52
+
53
53
  def self.from_ph(x)
54
54
  from_hpX(x)
55
55
  end
56
56
 
57
57
  def self.to_ld(x)
58
- log2(x)
58
+ Math.log(x) / Math.log(2)
59
59
  end
60
60
 
61
61
  def self.from_ld(x)
@@ -110,9 +110,8 @@ module Unitwise
110
110
  # @param scalar [Numeric] A linear scalar value
111
111
  # @return [Numeric] The equivalent magnitude on this scale
112
112
  # @api public
113
- def inverse_scalar(scalar = scalar)
113
+ def magnitude(scalar = scalar)
114
114
  self.class.send(:"to_#{function_name}", scalar)
115
115
  end
116
-
117
116
  end
118
117
  end
@@ -130,7 +130,7 @@ module Unitwise
130
130
  # measurement.to_foot # => <Unitwise::Measurement 4 foot>
131
131
  # @api semipublic
132
132
  def method_missing(meth, *args, &block)
133
- if args.empty? && !block_given? && (match = /\Ato_(\w+)\Z/.match(meth))
133
+ if args.empty? && !block_given? && (match = /\Ato_(\w+)\Z/.match(meth.to_s))
134
134
  begin
135
135
  convert_to(match[1])
136
136
  rescue ExpressionError
@@ -153,7 +153,7 @@ module Unitwise
153
153
  # @api private
154
154
  def converted_value(other_unit)
155
155
  if other_unit.special?
156
- other_unit.inverse_scalar scalar
156
+ other_unit.magnitude scalar
157
157
  else
158
158
  scalar / other_unit.scalar
159
159
  end
@@ -64,8 +64,12 @@ module Unitwise
64
64
  # @param scalar [Numeric] A linear scalar value
65
65
  # @return [Numeric] The equivalent magnitude on this scale
66
66
  # @api public
67
- def inverse_scalar(scalar = scalar)
68
- unit.inverse_scalar(scalar)
67
+ def magnitude(scalar = scalar)
68
+ if special?
69
+ unit.magnitude(scalar)
70
+ else
71
+ value * unit.magnitude
72
+ end
69
73
  end
70
74
 
71
75
  # The base terms this scale's unit is derived from
@@ -14,7 +14,7 @@ module Unitwise::Standard
14
14
  end
15
15
 
16
16
  def to_hash
17
- super.merge property: property, dim: dim
17
+ super.merge :property => property, :dim => dim
18
18
  end
19
19
 
20
20
  end
@@ -40,9 +40,9 @@ module Unitwise::Standard
40
40
  def to_hash
41
41
  hash = super()
42
42
  hash[:scale] = (special? ? function.to_hash : scale.to_hash)
43
- hash.merge({classification: classification,
44
- property: property, metric: metric?,
45
- special: special?, arbitrary: arbitrary?})
43
+ hash.merge({:classification => classification,
44
+ :property => property, :metric => metric?,
45
+ :special => special?, :arbitrary => arbitrary?})
46
46
  end
47
47
 
48
48
  end
@@ -28,7 +28,7 @@ module Unitwise::Standard
28
28
  end
29
29
 
30
30
  def to_hash
31
- {function_code: primary, value: value, unit_code: unit}
31
+ {:function_code => primary, :value => value, :unit_code => unit}
32
32
  end
33
33
 
34
34
  end
@@ -10,7 +10,7 @@ module Unitwise::Standard
10
10
  end
11
11
 
12
12
  def to_hash
13
- super().merge(scalar: scale)
13
+ super().merge(:scalar => scale)
14
14
  end
15
15
 
16
16
  end
@@ -19,7 +19,7 @@ module Unitwise::Standard
19
19
  end
20
20
 
21
21
  def to_hash
22
- {value: value, unit_code: primary_unit_code}
22
+ {:value => value, :unit_code => primary_unit_code}
23
23
  end
24
24
  end
25
25
  end
data/lib/unitwise/term.rb CHANGED
@@ -74,8 +74,8 @@ module Unitwise
74
74
  # @param scalar [Numeric] The scalar for which you want the magnitude
75
75
  # @return [Numeric] The magnitude on this scale.
76
76
  # @api public
77
- def inverse_scalar(scalar = scalar)
78
- calculate(atom ? atom.inverse_scalar(scalar) : 1)
77
+ def magnitude(scalar = scalar)
78
+ calculate(atom ? atom.magnitude(scalar) : 1)
79
79
  end
80
80
 
81
81
  # The base units this term is derived from
@@ -86,7 +86,7 @@ module Unitwise
86
86
  [self]
87
87
  else
88
88
  atom.scale.root_terms.map do |t|
89
- self.class.new(atom: t.atom, exponent: t.exponent * exponent)
89
+ self.class.new(:atom => t.atom, :exponent => t.exponent * exponent)
90
90
  end
91
91
  end
92
92
  end
@@ -100,7 +100,7 @@ module Unitwise
100
100
  elsif other.respond_to?(:atom)
101
101
  Unit.new([self, other])
102
102
  elsif other.is_a?(Numeric)
103
- self.class.new(to_hash.merge(factor: factor * other))
103
+ self.class.new(to_hash.merge(:factor => factor * other))
104
104
  end
105
105
  end
106
106
 
@@ -113,7 +113,7 @@ module Unitwise
113
113
  elsif other.respond_to?(:atom)
114
114
  Unit.new([self, other ** -1])
115
115
  elsif other.is_a?(Numeric)
116
- self.class.new(to_hash.merge(factor: factor / other))
116
+ self.class.new(to_hash.merge(:factor => factor / other))
117
117
  end
118
118
  end
119
119
 
@@ -122,7 +122,7 @@ module Unitwise
122
122
  # @return [Term]
123
123
  def **(other)
124
124
  if other.is_a?(Numeric)
125
- self.class.new(to_hash.merge(exponent: exponent * other))
125
+ self.class.new(to_hash.merge(:exponent => exponent * other))
126
126
  else
127
127
  fail TypeError, "Can't raise #{self} to #{other}."
128
128
  end
data/lib/unitwise/unit.rb CHANGED
@@ -10,12 +10,13 @@ module Unitwise
10
10
  # @param input [String, Unit, [Term]] A string expression, a unit, or a
11
11
  # collection of tems.
12
12
  def initialize(input)
13
- if input.respond_to?(:expression)
13
+ case input
14
+ when Compatible
14
15
  @expression = input.expression
15
- elsif input.respond_to?(:each)
16
- @terms = input
17
- else
16
+ when String, Symbol
18
17
  @expression = input.to_s
18
+ else
19
+ @terms = input
19
20
  end
20
21
  end
21
22
 
@@ -35,24 +36,23 @@ module Unitwise
35
36
  terms.count == 1 && terms.all?(&:special?)
36
37
  end
37
38
 
38
-
39
39
  def depth
40
40
  terms.map(&:depth).max + 1
41
41
  end
42
42
 
43
43
  def root_terms
44
- terms.flat_map(&:root_terms)
44
+ terms.map(&:root_terms).flatten
45
45
  end
46
46
 
47
- def scalar(x = 1)
47
+ def scalar(magnitude = 1)
48
48
  terms.reduce(1) do |prod, term|
49
- prod * term.scalar(x)
49
+ prod * term.scalar(magnitude)
50
50
  end
51
51
  end
52
52
 
53
- def inverse_scalar(x = 1)
53
+ def magnitude(scalar = scalar)
54
54
  terms.reduce(1) do |prod, term|
55
- prod * term.inverse_scalar(x)
55
+ prod * term.magnitude(scalar)
56
56
  end
57
57
  end
58
58
 
@@ -1,3 +1,3 @@
1
1
  module Unitwise
2
- VERSION = '0.6.0'
2
+ VERSION = '0.6.1'
3
3
  end
@@ -3,7 +3,7 @@ module ScaleTests
3
3
  def self.included(base)
4
4
  base.class_eval do
5
5
  subject { described_class.new(4, "J") }
6
-
6
+
7
7
  let(:mph) { Unitwise::Measurement.new(60, '[mi_i]/h') }
8
8
  let(:kmh) { Unitwise::Measurement.new(100, 'km/h') }
9
9
  let(:mile) { Unitwise::Measurement.new(3, '[mi_i]') }
@@ -32,21 +32,21 @@ module ScaleTests
32
32
  it "must be a collection of terms" do
33
33
  subject.must_respond_to(:root_terms)
34
34
  subject.root_terms.must_be_kind_of Enumerable
35
- subject.root_terms.sample.must_be_instance_of(Unitwise::Term)
35
+ subject.root_terms.first.must_be_instance_of(Unitwise::Term)
36
36
  end
37
37
  end
38
38
 
39
39
  describe "#terms" do
40
40
  it "must return an array of terms" do
41
41
  subject.terms.must_be_kind_of(Enumerable)
42
- subject.terms.sample.must_be_kind_of(Unitwise::Term)
42
+ subject.terms.first.must_be_kind_of(Unitwise::Term)
43
43
  end
44
44
  end
45
-
45
+
46
46
  describe "#atoms" do
47
47
  it "must return an array of atoms" do
48
48
  subject.atoms.must_be_kind_of(Enumerable)
49
- subject.atoms.sample.must_be_kind_of(Unitwise::Atom)
49
+ subject.atoms.first.must_be_kind_of(Unitwise::Atom)
50
50
  end
51
51
  end
52
52
 
@@ -58,9 +58,10 @@ module ScaleTests
58
58
  end
59
59
  end
60
60
 
61
- describe "#inverse_scalar" do
61
+ describe "#magnitude" do
62
62
  it "must return the magnitude" do
63
- cel.inverse_scalar.must_equal(22)
63
+ mph.magnitude.must_equal(60)
64
+ cel.magnitude.must_equal(22)
64
65
  end
65
66
  end
66
67
 
data/test/test_helper.rb CHANGED
@@ -1,5 +1,7 @@
1
- require 'coveralls'
2
- Coveralls.wear!
1
+ if RUBY_VERSION > '1.8.7'
2
+ require 'coveralls'
3
+ Coveralls.wear!
4
+ end
3
5
 
4
6
  require 'minitest/autorun'
5
7
  require 'minitest/pride'
@@ -28,19 +28,19 @@ describe Unitwise::Expression::Parser do
28
28
 
29
29
  describe "#factor" do
30
30
  it "must match positives and fixnums" do
31
- subject.factor.parse('3.2')[:factor].must_equal(fixnum: '3.2')
31
+ subject.factor.parse('3.2')[:factor].must_equal(:fixnum => '3.2')
32
32
  end
33
33
  it "must match negatives and integers" do
34
- subject.factor.parse('-5')[:factor].must_equal(integer: '-5')
34
+ subject.factor.parse('-5')[:factor].must_equal(:integer => '-5')
35
35
  end
36
36
  end
37
37
 
38
38
  describe "#exponent" do
39
39
  it "must match positives integers" do
40
- subject.exponent.parse('4')[:exponent].must_equal(integer: '4')
40
+ subject.exponent.parse('4')[:exponent].must_equal(:integer => '4')
41
41
  end
42
42
  it "must match negative integers" do
43
- subject.exponent.parse('-5')[:exponent].must_equal(integer: '-5')
43
+ subject.exponent.parse('-5')[:exponent].must_equal(:integer => '-5')
44
44
  end
45
45
  end
46
46
 
@@ -38,11 +38,11 @@ describe Numeric do
38
38
  end
39
39
 
40
40
  it "must not match 'foo'" do
41
- ->{ 1.foo }.must_raise NoMethodError
41
+ lambda { 1.foo }.must_raise NoMethodError
42
42
  end
43
43
 
44
44
  it "must not match 'to_foo'" do
45
- ->{ 1.to_foo }.must_raise NoMethodError
45
+ lambda { 1.to_foo }.must_raise NoMethodError
46
46
  end
47
47
 
48
48
  end
@@ -5,10 +5,11 @@ describe Unitwise::Functional do
5
5
  %w{cel degf hpX hpC tan100 ph ld ln lg 2lg}.each do |function|
6
6
  describe function do
7
7
  it 'should convert back and forth' do
8
- number = rand.round(5)
8
+ number = rand(1000) / 1000.0
9
9
  there = subject.send "to_#{function}", number
10
10
  back_again = subject.send "from_#{function}", there
11
- back_again.round(5).must_equal number
11
+ rounded_result = (back_again * 1000).round / 1000.0
12
+ rounded_result.must_equal number
12
13
  end
13
14
  end
14
15
  end
@@ -7,7 +7,7 @@ describe Unitwise::Measurement do
7
7
 
8
8
  describe "#new" do
9
9
  it "should raise an error for unknown units" do
10
- ->{ Unitwise::Measurement.new(1,"funkitron") }.must_raise(Unitwise::ExpressionError)
10
+ lambda { Unitwise::Measurement.new(1,"funkitron") }.must_raise(Unitwise::ExpressionError)
11
11
  end
12
12
  end
13
13
 
@@ -16,7 +16,7 @@ describe Unitwise::Measurement do
16
16
  mph.convert_to('km/h').value.must_equal 96.56063999999999
17
17
  end
18
18
  it "must raise an error if the units aren't similar" do
19
- ->{ mph.convert_to('N') }.must_raise Unitwise::ConversionError
19
+ lambda { mph.convert_to('N') }.must_raise Unitwise::ConversionError
20
20
  end
21
21
  it "must convert special units to their base units" do
22
22
  cel.convert_to('K').value.must_equal 295.15
@@ -110,7 +110,7 @@ describe Unitwise::Measurement do
110
110
  exp.unit.to_s.must_equal "1/[mi_i]3"
111
111
  end
112
112
  it "must not raise to a weird power" do
113
- -> { mile ** 'weird' }.must_raise TypeError
113
+ lambda { mile ** 'weird' }.must_raise TypeError
114
114
  end
115
115
  end
116
116
 
@@ -120,7 +120,7 @@ describe Unitwise::Measurement do
120
120
  meter.coerce(5).must_equal [ Unitwise::Measurement.new(5, '1'), meter ]
121
121
  end
122
122
  it "should raise an error for other crap" do
123
- -> { meter.coerce("foo") }.must_raise TypeError
123
+ lambda { meter.coerce("foo") }.must_raise TypeError
124
124
  end
125
125
  end
126
126
 
@@ -139,11 +139,11 @@ describe Unitwise::Measurement do
139
139
  end
140
140
 
141
141
  it "must not convert 'foo'" do
142
- ->{ meter.foo }.must_raise NoMethodError
142
+ lambda { meter.foo }.must_raise NoMethodError
143
143
  end
144
144
 
145
145
  it "must not convert 'to_foo'" do
146
- ->{ meter.to_foo }.must_raise NoMethodError
146
+ lambda { meter.to_foo }.must_raise NoMethodError
147
147
  end
148
148
 
149
149
  end
@@ -12,7 +12,7 @@ describe Unitwise::Prefix do
12
12
  describe "::all" do
13
13
  it "should be an array of prefixes" do
14
14
  subject.all.must_be_instance_of Array
15
- subject.all.sample.must_be_instance_of Unitwise::Prefix
15
+ subject.all.first.must_be_instance_of Unitwise::Prefix
16
16
  end
17
17
  end
18
18
 
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
 
3
3
  describe Unitwise::Term do
4
4
  describe "instance" do
5
- subject { Unitwise::Term.new(atom: 'J', prefix: 'k')}
5
+ subject { Unitwise::Term.new(:atom => 'J', :prefix => 'k')}
6
6
  describe "#atom" do
7
7
  it "should be an atom" do
8
8
  subject.atom.must_be_instance_of Unitwise::Atom
@@ -24,7 +24,7 @@ describe Unitwise::Term do
24
24
  describe "#root_terms" do
25
25
  it "should be an array of terms" do
26
26
  subject.root_terms.must_be_kind_of Array
27
- subject.root_terms.sample.must_be_instance_of Unitwise::Term
27
+ subject.root_terms.first.must_be_instance_of Unitwise::Term
28
28
  end
29
29
  end
30
30
 
@@ -12,7 +12,7 @@ describe Unitwise::Unit do
12
12
  it "must be a collection of terms" do
13
13
  ms2.must_respond_to :terms
14
14
  ms2.terms.must_be_kind_of Enumerable
15
- ms2.terms.sample.must_be_instance_of Unitwise::Term
15
+ ms2.terms.first.must_be_instance_of Unitwise::Term
16
16
  end
17
17
  end
18
18
 
@@ -20,7 +20,7 @@ describe Unitwise::Unit do
20
20
  it "must be an array of Terms" do
21
21
  ms2.must_respond_to :terms
22
22
  ms2.root_terms.must_be_kind_of Array
23
- ms2.root_terms.sample.must_be_instance_of Unitwise::Term
23
+ ms2.root_terms.first.must_be_instance_of Unitwise::Term
24
24
  end
25
25
  end
26
26
 
@@ -50,15 +50,17 @@ describe Unitwise::Unit do
50
50
  describe "#*" do
51
51
  it "should multiply units" do
52
52
  mult = kg * ms2
53
- mult.expression.to_s.must_equal "kg.m/s2"
53
+ mult.expression.to_s.must_match /kg.*\/s2/
54
+ mult.expression.to_s.must_match /m.*\/s2/
54
55
  end
55
56
  end
56
57
 
57
58
  describe "#/" do
58
59
  it "should divide units" do
59
60
  div = kg / ms2
60
- div.expression.to_s.must_equal "kg.s2/m"
61
+ div.expression.to_s.must_match /kg.*\/m/
62
+ div.expression.to_s.must_match /s2.*\/m/
61
63
  end
62
64
  end
63
65
 
64
- end
66
+ end
data/unitwise.gemspec CHANGED
@@ -20,13 +20,19 @@ Gem::Specification.new do |gem|
20
20
  gem.test_files = gem.files.grep(/^test\//)
21
21
  gem.require_paths = ['lib']
22
22
 
23
- gem.add_dependency 'liner', '~> 0.2'
24
- gem.add_dependency 'signed_multiset', '~> 0.2'
25
- gem.add_dependency 'parslet', '~> 1.5'
23
+ gem.add_dependency 'liner', '~> 0.2.4'
24
+ gem.add_dependency 'signed_multiset', '~> 0.2.0'
25
+
26
+ if RUBY_VERSION > '1.8.7'
27
+ gem.add_dependency 'parslet', '~> 1.5'
28
+ gem.add_development_dependency 'nokogiri', '~> 1.5'
29
+ gem.add_development_dependency 'coveralls', '~> 0.6'
30
+ else
31
+ gem.add_dependency 'parslet', '~> 1.5.0'
32
+ gem.add_development_dependency 'nokogiri', '~> 1.5.10'
33
+ end
26
34
 
27
35
  gem.add_development_dependency 'minitest', '>= 5.0'
28
36
  gem.add_development_dependency 'rake', '>= 10.0'
29
37
  gem.add_development_dependency 'nori', '~> 2.3'
30
- gem.add_development_dependency 'nokogiri', '~> 1.6'
31
- gem.add_development_dependency 'coveralls', '~> 0.6'
32
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unitwise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Lewis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-14 00:00:00.000000000 Z
11
+ date: 2014-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: liner
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.2'
19
+ version: 0.2.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.2'
26
+ version: 0.2.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: signed_multiset
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.2'
33
+ version: 0.2.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.2'
40
+ version: 0.2.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: parslet
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -53,75 +53,75 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.5'
55
55
  - !ruby/object:Gem::Dependency
56
- name: minitest
56
+ name: nokogiri
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '5.0'
61
+ version: '1.5'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '5.0'
68
+ version: '1.5'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rake
70
+ name: coveralls
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '10.0'
75
+ version: '0.6'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '10.0'
82
+ version: '0.6'
83
83
  - !ruby/object:Gem::Dependency
84
- name: nori
84
+ name: minitest
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '2.3'
89
+ version: '5.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '2.3'
96
+ version: '5.0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: nokogiri
98
+ name: rake
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: '1.6'
103
+ version: '10.0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: '1.6'
110
+ version: '10.0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: coveralls
112
+ name: nori
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0.6'
117
+ version: '2.3'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0.6'
124
+ version: '2.3'
125
125
  description: Ruby implementation of the Unified Code for Units of Measure (UCUM)
126
126
  email:
127
127
  - josh.w.lewis@gmail.com