aeonscope-number_to_fraction 1.0.0 → 1.0.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/CHANGELOG.rdoc +4 -0
- data/README.rdoc +5 -5
- data/VERSION.yml +1 -1
- data/lib/number_to_fraction.rb +1 -0
- data/spec/number_to_fraction_spec.rb +8 -0
- metadata +1 -1
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= Overview
|
2
2
|
|
3
|
-
A helper that can format a number into a fraction. Unfortunately, this only handles the "pretty printing" of
|
3
|
+
A helper that can format a number into a fraction. Unfortunately, this only handles the "pretty printing" of fractions less than 1/10th at the moment (as a better algorithm needs to be used for more complex number cases).
|
4
4
|
|
5
5
|
= License
|
6
6
|
|
@@ -19,18 +19,18 @@ See the CHANGELOG file for more info.
|
|
19
19
|
|
20
20
|
Type the following from the command line to install:
|
21
21
|
|
22
|
-
* *UNIX*: sudo gem install aeonscope-
|
23
|
-
* *Windows*: gem install aeonscope-
|
22
|
+
* *UNIX*: sudo gem install aeonscope-number_to_fraction
|
23
|
+
* *Windows*: gem install aeonscope-number_to_fraction
|
24
24
|
|
25
25
|
Update your environment.rb file to include the new gem:
|
26
26
|
|
27
|
-
* config.gem "aeonscope-
|
27
|
+
* config.gem "aeonscope-number_to_fraction", :lib => "number_to_fraction", :source => "http://gems.github.com"
|
28
28
|
|
29
29
|
= Usage
|
30
30
|
|
31
31
|
Example:
|
32
32
|
|
33
|
-
|
33
|
+
number_to_fraction 3.75
|
34
34
|
|
35
35
|
Result:
|
36
36
|
|
data/VERSION.yml
CHANGED
data/lib/number_to_fraction.rb
CHANGED
@@ -18,6 +18,7 @@ module ActionView
|
|
18
18
|
number = number.to_s.strip
|
19
19
|
options.reverse_merge! :precision => 3
|
20
20
|
whole, numerator, denominator = nil
|
21
|
+
number.chomp!(".0") if number.end_with? ".0" # Remove zero fractionals.
|
21
22
|
if number.include? '.'
|
22
23
|
whole, numerator = number.split '.'
|
23
24
|
rational = Rational(numerator.ljust(options[:precision], '0').to_i, (10 ** options[:precision]))
|
@@ -19,6 +19,14 @@ describe "Number to Fraction" do
|
|
19
19
|
number_to_fraction(1).should == '1'
|
20
20
|
end
|
21
21
|
|
22
|
+
it "should be 10" do
|
23
|
+
number_to_fraction(10).should == "10"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should be 10 even when the fractional is zero" do
|
27
|
+
number_to_fraction(10.0).should == "10"
|
28
|
+
end
|
29
|
+
|
22
30
|
it "should be 1/3" do
|
23
31
|
number_to_fraction(0.33).should == "1/3"
|
24
32
|
end
|