epitools 0.5.133 → 0.5.136
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +5 -7
- data/VERSION +1 -1
- data/lib/epitools/autoloads.rb +5 -2
- data/lib/epitools/browser/cache.rb +1 -1
- data/lib/epitools/browser.rb +4 -4
- data/lib/epitools/clitools.rb +21 -4
- data/lib/epitools/core_ext/array.rb +1 -1
- data/lib/epitools/core_ext/numbers.rb +34 -3
- data/lib/epitools/core_ext/object.rb +4 -1
- data/lib/epitools/core_ext/string.rb +99 -3
- data/lib/epitools/fraction.rb +131 -0
- data/lib/epitools/gem_ext/oga.rb +31 -0
- data/lib/epitools/hexdump.rb +1 -1
- data/lib/epitools/minimal.rb +2 -3
- data/lib/epitools/path.rb +34 -19
- data/lib/epitools/pretty_backtrace.rb +1 -1
- data/lib/epitools/rash.rb +1 -1
- data/lib/epitools/term.rb +73 -15
- data/spec/core_ext_spec.rb +26 -2
- data/spec/fraction_spec.rb +53 -0
- data/spec/numwords_spec.rb +2 -5
- data/spec/path_spec.rb +14 -4
- data/spec/sys_spec.rb +5 -0
- data/spec/zopen_spec.rb +37 -37
- metadata +8 -6
- data/lib/epitools/ratio.rb +0 -78
- /data/spec/{browser_spec.rb → manual/browser_spec.rb} +0 -0
- /data/spec/{wm_spec.rb → manual/wm_spec.rb} +0 -0
data/lib/epitools/ratio.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# The ratio between two numbers (eg: 2:1, 3:4)
|
3
|
-
#
|
4
|
-
# Can be compared, added, "percent"ed, "to_f"ed, and displayed.
|
5
|
-
#
|
6
|
-
class Ratio
|
7
|
-
|
8
|
-
include Comparable
|
9
|
-
|
10
|
-
def <=>(other)
|
11
|
-
to_f <=> other.to_f
|
12
|
-
end
|
13
|
-
|
14
|
-
attr_accessor :first, :last
|
15
|
-
|
16
|
-
def self.[](*args)
|
17
|
-
new(*args)
|
18
|
-
end
|
19
|
-
|
20
|
-
#
|
21
|
-
# `first` is the top part of the ratio, `last` is the bottom (eg: `first/last`)
|
22
|
-
#
|
23
|
-
def initialize(first, last=1)
|
24
|
-
@first = first
|
25
|
-
@last = last
|
26
|
-
end
|
27
|
-
|
28
|
-
#
|
29
|
-
# Returns a string representation: "a/b"
|
30
|
-
#
|
31
|
-
def to_s
|
32
|
-
"#{@first}/#{@last}"
|
33
|
-
end
|
34
|
-
alias_method :ratio, :to_s
|
35
|
-
|
36
|
-
#
|
37
|
-
# Returns the ratio as a float. (eg: Ratio[1,2].to_f == 0.5)
|
38
|
-
#
|
39
|
-
def to_f
|
40
|
-
if @last == 0
|
41
|
-
0.0
|
42
|
-
else
|
43
|
-
@first.to_f / @last
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
#
|
48
|
-
# Returns a string representing the number in percent
|
49
|
-
#
|
50
|
-
def percent
|
51
|
-
"%0.1f%%" % (to_f * 100)
|
52
|
-
end
|
53
|
-
alias_method :to_percent, :percent
|
54
|
-
|
55
|
-
#
|
56
|
-
# "#<Ratio: 1/2>"
|
57
|
-
#
|
58
|
-
def inspect
|
59
|
-
"#<Ratio: #{to_s}>"
|
60
|
-
end
|
61
|
-
|
62
|
-
#
|
63
|
-
# Adds together the tops and bottoms of the ratios.
|
64
|
-
#
|
65
|
-
# Example: For the ratios `a/c` and `b/d`, returns `a+b/c+d`
|
66
|
-
#
|
67
|
-
def +(other)
|
68
|
-
Ratio.new( first+other.first, last+other.last)
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
#
|
74
|
-
# Function-style wrapper
|
75
|
-
#
|
76
|
-
def Ratio(*args)
|
77
|
-
Ratio.new(*args)
|
78
|
-
end
|
File without changes
|
File without changes
|