measurement 0.2.3 → 0.2.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.2.3.1 Fix for missing file
2
+
1
3
  v0.2.3 Group formats
2
4
 
3
5
  v0.2.2 Better formatting functions
data/Manifest CHANGED
@@ -6,6 +6,7 @@ Rakefile
6
6
  lib/measurement.rb
7
7
  lib/measurement/length.rb
8
8
  lib/measurement/unit.rb
9
+ lib/measurement/unit_group.rb
9
10
  lib/measurement/weight.rb
10
11
  spec/lib/length_spec.rb
11
12
  spec/lib/measurement_spec.rb
@@ -0,0 +1,24 @@
1
+ module Measurement
2
+ # This class is a group of units. To specify that a unit
3
+ # is in a group pass the group option to Measurement::Base#unit
4
+ class UnitGroup
5
+ def initialize(units)
6
+ @units = units.sort.reverse
7
+ end
8
+
9
+ def format(amount, precision = 0)
10
+ units = @units.dup
11
+ strs = []
12
+
13
+ while unit = units.shift
14
+ n_in = unit.to(amount)
15
+ n_in = n_in.floor unless units.empty?
16
+ n_out = unit.from(n_in)
17
+ amount -= n_out
18
+ strs << unit.format(n_out, precision) unless n_out == 0
19
+ end
20
+
21
+ strs.join(' ')
22
+ end
23
+ end
24
+ end
data/measurement.gemspec CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{measurement}
5
- s.version = "0.2.3"
5
+ s.version = "0.2.3.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Jeremy Wells"]
9
9
  s.date = %q{2010-03-01}
10
10
  s.description = %q{A library for holding, converting and formatting measurements}
11
11
  s.email = %q{jemmyw@gmail.com}
12
- s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.rdoc", "lib/measurement.rb", "lib/measurement/length.rb", "lib/measurement/unit.rb", "lib/measurement/weight.rb"]
13
- s.files = ["CHANGELOG", "LICENSE", "Manifest", "README.rdoc", "Rakefile", "lib/measurement.rb", "lib/measurement/length.rb", "lib/measurement/unit.rb", "lib/measurement/weight.rb", "spec/lib/length_spec.rb", "spec/lib/measurement_spec.rb", "spec/lib/unit_spec.rb", "spec/lib/weight_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "measurement.gemspec"]
12
+ s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.rdoc", "lib/measurement.rb", "lib/measurement/length.rb", "lib/measurement/unit.rb", "lib/measurement/unit_group.rb", "lib/measurement/weight.rb"]
13
+ s.files = ["CHANGELOG", "LICENSE", "Manifest", "README.rdoc", "Rakefile", "lib/measurement.rb", "lib/measurement/length.rb", "lib/measurement/unit.rb", "lib/measurement/unit_group.rb", "lib/measurement/weight.rb", "spec/lib/length_spec.rb", "spec/lib/measurement_spec.rb", "spec/lib/unit_spec.rb", "spec/lib/weight_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "measurement.gemspec"]
14
14
  s.homepage = %q{}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Measurement", "--main", "README.rdoc"]
16
16
  s.require_paths = ["lib"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: measurement
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Wells
@@ -26,6 +26,7 @@ extra_rdoc_files:
26
26
  - lib/measurement.rb
27
27
  - lib/measurement/length.rb
28
28
  - lib/measurement/unit.rb
29
+ - lib/measurement/unit_group.rb
29
30
  - lib/measurement/weight.rb
30
31
  files:
31
32
  - CHANGELOG
@@ -36,6 +37,7 @@ files:
36
37
  - lib/measurement.rb
37
38
  - lib/measurement/length.rb
38
39
  - lib/measurement/unit.rb
40
+ - lib/measurement/unit_group.rb
39
41
  - lib/measurement/weight.rb
40
42
  - spec/lib/length_spec.rb
41
43
  - spec/lib/measurement_spec.rb