quantify 3.1.0 → 3.1.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/VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.0
1
+ 3.1.1
@@ -191,9 +191,7 @@ module Quantify
191
191
  end
192
192
 
193
193
  def self.dimensionless
194
- Unit::Base.new(:dimensions => 'dimensionless') do |unit|
195
- unit.acts_as_alternative_unit = false
196
- end
194
+ Unit::Base.new(:dimensions => 'dimensionless')
197
195
  end
198
196
 
199
197
  # Retrieve an object representing the specified unit.
@@ -329,8 +327,8 @@ module Quantify
329
327
  while term = string.starts_with_valid_unit_term? do
330
328
  if term =~ /^#{UNIT_PREFIX_TERMS_REGEX}$/
331
329
  current_exponent = Unit.exponent_term_to_number(term)
332
- elsif term =~ /^#{UNIT_SUFFIX_TERMS_REGEX}$/
333
- units.last.index *= Unit.exponent_term_to_number(term)
330
+ elsif term =~ /^#{UNIT_SUFFIX_TERMS_REGEX}$/
331
+ units.last.index *= Unit.exponent_term_to_number(term) unless units.empty?
334
332
  elsif term =~ /^#{UNIT_DENOMINATOR_REGEX}/
335
333
  is_denominator = true
336
334
  else
@@ -424,7 +422,6 @@ module Quantify
424
422
  def self.terms_for_regex(klass,method,attribute)
425
423
  list = klass.send(method).map { |item| item.send(attribute).gsub("/","\\/").gsub("^","\\^") }
426
424
  list.map! { |item| item.downcase } if attribute == :name
427
- list.reject! { |item| item == "" }
428
425
  list.sort {|x, y| y.size <=> x.size }.join("|")
429
426
  end
430
427
 
data/quantify.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "quantify"
8
- s.version = "3.1.0"
8
+ s.version = "3.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andrew Berkeley"]
12
- s.date = "2011-12-21"
12
+ s.date = "2011-12-22"
13
13
  s.description = "A gem to support physical quantities and unit conversions"
14
14
  s.email = "andrew.berkeley.is@googlemail.com"
15
15
  s.extra_rdoc_files = [
@@ -185,6 +185,48 @@ describe Quantity do
185
185
  quantities.first.unit.symbol.should == 'ft²'
186
186
  end
187
187
 
188
+ it "should return dimensionless quantity when 'squared' suffix used without a unit" do
189
+ quantities = Quantity.parse "25 squared"
190
+ quantities.first.value.should == 25
191
+ quantities.first.unit.name.should == ''
192
+ quantities.first.unit.symbol.should == ''
193
+ end
194
+
195
+ it "should return unsquared quantity when 'squared' suffix used unrelated to unit" do
196
+ quantities = Quantity.parse "25 grams some more text and then squared"
197
+ quantities.first.value.should == 25
198
+ quantities.first.unit.name.should == 'gram'
199
+ quantities.first.unit.symbol.should == 'g'
200
+ end
201
+
202
+ it "should return unsquared quantity when 'square' suffix used" do
203
+ quantities = Quantity.parse "25 grams square"
204
+ quantities.first.value.should == 25
205
+ quantities.first.unit.name.should == 'gram'
206
+ quantities.first.unit.symbol.should == 'g'
207
+ end
208
+
209
+ it "should return dimensionless quantity when 'square' prefix used without a unit" do
210
+ quantities = Quantity.parse "25 square"
211
+ quantities.first.value.should == 25
212
+ quantities.first.unit.name.should == ''
213
+ quantities.first.unit.symbol.should == ''
214
+ end
215
+
216
+ it "should return dimensionless quantity when 'cubed' suffix used without a unit" do
217
+ quantities = Quantity.parse "25 cubed"
218
+ quantities.first.value.should == 25
219
+ quantities.first.unit.name.should == ''
220
+ quantities.first.unit.symbol.should == ''
221
+ end
222
+
223
+ it "should return dimensionless quantity when 'cubic' prefix used without a unit" do
224
+ quantities = Quantity.parse "25 cubic"
225
+ quantities.first.value.should == 25
226
+ quantities.first.unit.name.should == ''
227
+ quantities.first.unit.symbol.should == ''
228
+ end
229
+
188
230
  it "should create valid instance from string with 'cubed' suffix descriptor" do
189
231
  quantities = Quantity.parse "25 feet cubed"
190
232
  quantities.first.value.should == 25
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quantify
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
8
  - 1
9
- - 0
10
- version: 3.1.0
9
+ - 1
10
+ version: 3.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrew Berkeley
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-12-21 00:00:00 Z
18
+ date: 2011-12-22 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  requirement: &id001 !ruby/object:Gem::Requirement