unitwise 1.0.2 → 1.0.3

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: 410fb733b657a34122237793d03bf634fa0676b2
4
- data.tar.gz: 57ab5cfe90d3bfb9dea058ea3b85904b3bb451dd
3
+ metadata.gz: 4d56341dd889cc55e9289497dd98cb6919b4c407
4
+ data.tar.gz: 3edb93758dcb292a7a6894228470859252e8fe30
5
5
  SHA512:
6
- metadata.gz: 0171c1aef8b9daf3e07a89959bbde2ee947854c51b6f7be0c1d569e140b0e9f24e95ec9a455babcb489d105c1656928cb207180b935fc02b329c330c9e3a41b8
7
- data.tar.gz: 389f2c83e8505e1e7e6df4b8a9aeb6ae79869e2693dd3bb9d9476667ed440823f32faa63403c78a234a7fbdb83fd46d7e48072bed52c1946615bd408ef13bf6d
6
+ metadata.gz: 3feb6a4ca9b67743dd9c3e3a66d9f142c93096fe95127eba58d7d579beee693f85e93a7d841e89662cdb3704f14785bc02ea928fa48481257723372eac50bf8d
7
+ data.tar.gz: 868522db37708233ea85b08ebb1aa9ec7407c0187f638a99f3878b69262230f43d6b4ac110423792963ad631a7cf6c97d2346b84d467f812b4b2a0e73850f6fe
data/CHANGELOG.md CHANGED
@@ -5,10 +5,14 @@ version 1.0.0.
5
5
 
6
6
  Unitwise uses semantic versioning.
7
7
 
8
- ## 1.0.2 - 2014-09-14
8
+ ## 1.0.3 - 2014-10-05
9
9
 
10
- ## Fixed
10
+ ### Added
11
+ - Unitwise.valid? for checking validity of expressions
11
12
 
13
+ ## 1.0.2 - 2014-09-14
14
+
15
+ ### Fixed
12
16
  - Decomposer caching is now a little smarter. This resulted in a mild
13
17
  performance increase.
14
18
 
data/lib/unitwise.rb CHANGED
@@ -31,6 +31,18 @@ module Unitwise
31
31
  def self.search(term)
32
32
  Search.search(term)
33
33
  end
34
+
35
+ # Determine if a given string is a valid unit expression
36
+ # @param expression [String]
37
+ # @return [true, false]
38
+ # @api public
39
+ def self.valid?(expression)
40
+ begin
41
+ !!Unitwise::Expression.decompose(expression)
42
+ rescue ExpressionError
43
+ false
44
+ end
45
+ end
34
46
 
35
47
  # The system path for the installed gem
36
48
  # @api private
@@ -1,3 +1,3 @@
1
1
  module Unitwise
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
3
3
  end
@@ -19,6 +19,15 @@ describe Unitwise do
19
19
  end
20
20
  end
21
21
 
22
+ describe 'valid?' do
23
+ it 'should reutrn true for valid unit strings' do
24
+ Unitwise.valid?('millimeter').must_equal true
25
+ end
26
+ it 'should return false for invalid unit strings' do
27
+ Unitwise.valid?('foo').must_equal false
28
+ end
29
+ end
30
+
22
31
  it "should have a path" do
23
32
  Unitwise.path.must_match(/unitwise$/)
24
33
  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: 1.0.2
4
+ version: 1.0.3
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-09-14 00:00:00.000000000 Z
11
+ date: 2014-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: liner
@@ -242,4 +242,3 @@ test_files:
242
242
  - test/unitwise/term_test.rb
243
243
  - test/unitwise/unit_test.rb
244
244
  - test/unitwise_test.rb
245
- has_rdoc: