Permalink
Browse files

Add small readme

  • Loading branch information...
1 parent bbff10e commit 6a560766cb0dac8d18d5405654966aa02185abd5 Markus Schirp committed Feb 10, 2012
Showing with 16 additions and 9 deletions.
  1. +9 −0 README.md
  2. +1 −0 TODO
  3. +1 −0 lib/sunits.rb
  4. +4 −8 lib/sunits/unit.rb
  5. +1 −1 sunits.gemspec
View
@@ -0,0 +1,9 @@
+SUnits
+======
+
+Small units implementation. It has less features when compared to ruby-units.
+But it is much smaller! Also it does not require mathn, so 1 / 2 is till 0 when
+you use this library.
+
+This library is only tested and usable under MRI 1.9, it does not use an 1.9
+syntax, so it should be easily portable.
View
1 TODO
@@ -1,2 +1,3 @@
* Remove more custom typecasting logic? Can we coerce to SUnit::Unit?
* Use code metrics
+* Make buildin units configurable
View
@@ -1,3 +1,4 @@
+require 'backports'
require 'rational'
require 'virtus/value_object'
require 'sunits/virtus'
View
@@ -1,6 +1,3 @@
-# Small and imcomplete units implementation. But serves well
-# for my use case where ruby-units behaviour of requireing mathn is
-# unacceptable.
module SUnits
class Unit
include Virtus::ValueObject
@@ -32,9 +29,8 @@ def initialize(*arguments)
raise ArgumentError,"cannot convert: #{scalar} into Rational"
end
- # compact is needed for ruby-1.8.7 and rbx
- numerators = [*numerators].compact
- denominators = [*denominators].compact
+ numerators = [*numerators]
+ denominators = [*denominators]
numerators.map! do |numerator|
unit_scale,numerator = Helper.find_unit(numerator)
@@ -54,8 +50,8 @@ def initialize(*arguments)
# Symbol#<=> is only present on mri 1.9
- self.numerators = numerators. sort_by(&:to_s).freeze
- self.denominators = denominators.sort_by(&:to_s).freeze
+ self.numerators = numerators. sort.freeze
+ self.denominators = denominators.sort.freeze
freeze
View
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
s.rubygems_version = '1.8.10'
- s.add_dependency('virtus', '~> 0.2.0')
+ s.add_runtime_dependency('virtus', '~> 0.2.0')
s.add_development_dependency('rspec', '~> 2.8.0')
end

0 comments on commit 6a56076

Please sign in to comment.