friendly_extensions 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/array.rb +1 -5
- data/lib/numbers.rb +59 -60
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c9dd59949c5e27d976e6862b96e57a80a9a638f
|
4
|
+
data.tar.gz: 570d44c51967a217e540f1a7d6bb91ae4ea67713
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60720aa317b66cd7be453986e37f12d5ad0b48b27ddef2215a78fdd480fe1d35505335bb3b1384d2c5dae1c14f13213d9ff7144099e95b409bd2175c27e2cee8
|
7
|
+
data.tar.gz: 21e68d908e8ba6f0a809179ee6f83571b47dc9870f7f90b918c8d7ae66ea13c5a1a63657d6114a8f54b761234f27ddf746a2accb0819b91afb1846fbf23bbfac
|
data/lib/array.rb
CHANGED
data/lib/numbers.rb
CHANGED
@@ -1,56 +1,56 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
# Numeric Extensions
|
3
3
|
module Numbers
|
4
|
-
|
4
|
+
|
5
5
|
Numeric.class_eval do
|
6
|
-
|
6
|
+
|
7
7
|
# Convert Number to numeric german style with precision
|
8
8
|
def to_euro(label = nil, options = {})
|
9
9
|
options[:precision] ||= 2
|
10
|
-
|
10
|
+
|
11
11
|
options[:precision] = 0 if options[:fix_int] == true && self.is_a?(Integer)
|
12
|
-
|
12
|
+
|
13
13
|
result = ActionController::Base.helpers.number_with_precision(self, :precision => options[:precision], :separator => ",", :delimiter => ".")
|
14
|
-
|
14
|
+
|
15
15
|
if options[:pre] == true && self > 0
|
16
16
|
result = "+#{result}"
|
17
17
|
elsif options[:pre] == true && self < 0
|
18
18
|
result = "-#{result}"
|
19
|
-
end
|
20
|
-
|
21
|
-
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
22
|
if !label.blank?
|
23
23
|
return [result, label].join(" ").html_safe
|
24
24
|
else
|
25
25
|
return result
|
26
|
-
end
|
26
|
+
end
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
# Convert Number to numeric german style without precision
|
30
30
|
def to_de(label=nil)
|
31
31
|
self.to_euro(label, :precision => 0)
|
32
|
-
end
|
33
|
-
|
32
|
+
end
|
33
|
+
|
34
34
|
def to_a
|
35
35
|
[self]
|
36
|
-
end
|
37
|
-
|
36
|
+
end
|
37
|
+
|
38
38
|
# Inflate number, y = duration of years, f = percentage
|
39
39
|
# tested
|
40
40
|
def infla(y=40,f=2)
|
41
41
|
self.to_f*(f.to_q**y)
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
# Deflate number, y = duration of years, f = percentage
|
45
45
|
# tested
|
46
46
|
def defla(y=40,f=2)
|
47
47
|
self.to_f*((1-(f.fdiv(100)))**y)
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
# Prüfen, welche Zahl aus dem Array am nächsten an der aktuellen Dran ist
|
51
51
|
# tested
|
52
52
|
def get_closest(nrs = [], lim = :ceil)
|
53
|
-
|
53
|
+
|
54
54
|
com = {}
|
55
55
|
com_a = []
|
56
56
|
nrs.each do |n|
|
@@ -61,88 +61,92 @@ module Numbers
|
|
61
61
|
x = ((self-0.001)-n).abs
|
62
62
|
else
|
63
63
|
raise ArgumentError, "lim must be :ceil or :floor"
|
64
|
-
end
|
64
|
+
end
|
65
65
|
com.merge!(x => n)
|
66
66
|
com_a << x
|
67
67
|
end
|
68
|
-
return com[com_a.min]
|
69
|
-
end
|
70
|
-
|
68
|
+
return com[com_a.min]
|
69
|
+
end
|
70
|
+
|
71
71
|
# tested
|
72
72
|
def min(ref)
|
73
73
|
[self.to_f, ref.to_f].min
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
# tested
|
77
77
|
def max(ref)
|
78
78
|
[self.to_f, ref.to_f].max
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
# Wert zwischen den Grenzen, ansonsten ober-oder unterkante
|
82
82
|
# tested
|
83
83
|
def min_max(m1, m2)
|
84
84
|
self.min(m2).max(m1)
|
85
|
-
end
|
86
|
-
|
85
|
+
end
|
86
|
+
|
87
87
|
# => tested
|
88
88
|
def fdiv(d)
|
89
89
|
self.to_f/d
|
90
90
|
end
|
91
|
-
|
92
|
-
|
91
|
+
|
92
|
+
|
93
93
|
# Finanzmathematik, Zinsen und so
|
94
94
|
def to_q
|
95
95
|
1+(self/100.0)
|
96
|
-
end
|
97
|
-
|
96
|
+
end
|
97
|
+
|
98
98
|
def alpha_sum(u,o)
|
99
99
|
(self**u - self**(o+1)).fdiv(1-self)
|
100
|
-
end
|
101
|
-
|
102
|
-
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
103
|
def to_time(options = {})
|
104
104
|
values = [ self.to_i/3600, self.to_i / 60 % 60, self.to_i%60 ].map{ |t| t.to_s.rjust(2, '0') }
|
105
105
|
if options[:split] == true
|
106
106
|
return {:h => values[0].round, :m => values[1].round, :s => values[2].round}
|
107
107
|
elsif options[:discard_hour] == true && values[0] == "00"
|
108
108
|
return values[1,2].join(':')
|
109
|
-
else
|
109
|
+
else
|
110
110
|
return values.join(':')
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
114
|
def deg2rad
|
115
115
|
self * Math::PI / 180
|
116
|
-
end
|
117
|
-
|
118
|
-
|
119
|
-
|
116
|
+
end
|
117
|
+
|
118
|
+
def nan?
|
119
|
+
self.to_f.nan?
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
end
|
120
124
|
|
121
125
|
Integer.class_eval do
|
122
|
-
|
123
|
-
|
124
|
-
|
126
|
+
|
127
|
+
|
128
|
+
|
125
129
|
def odd?
|
126
130
|
self%2 == 0
|
127
131
|
end
|
128
|
-
|
132
|
+
|
129
133
|
def even?
|
130
134
|
!self.odd?
|
131
|
-
end
|
132
|
-
|
135
|
+
end
|
136
|
+
|
133
137
|
|
134
138
|
# Cals
|
135
139
|
def to_years(options = {:s_years => "Jahre", :s_months => "Monate", :s_sep => "und"})
|
136
140
|
x = [self/12, self%12]
|
137
141
|
"#{x[0]} #{options[:s_years]} #{options[:s_sep]} #{x[1]} #{options[:s_months]}"
|
138
142
|
end
|
139
|
-
|
143
|
+
|
140
144
|
def days_to_months(options = {:s_days => "Tage", :s_months => "Monate", :s_sep => "und"})
|
141
145
|
x = [self/30, self%30]
|
142
146
|
"#{x[0]} #{options[:s_months]} #{options[:s_sep]} #{x[1]} #{options[:s_days]}"
|
143
|
-
end
|
144
|
-
|
145
|
-
|
147
|
+
end
|
148
|
+
|
149
|
+
|
146
150
|
# Split number in smallest prime factors
|
147
151
|
def prime_factors(options = {})
|
148
152
|
options[:nrs] ||= Math.sqrt(self).floor.prime_numbers
|
@@ -151,11 +155,11 @@ module Numbers
|
|
151
155
|
return [n, (self/n).prime_factors(:nrs => options[:nrs])].flatten.except(1)
|
152
156
|
elsif i == options[:nrs].size-1
|
153
157
|
return [self]
|
154
|
-
end
|
158
|
+
end
|
155
159
|
end
|
156
160
|
end
|
157
|
-
|
158
|
-
# Create list with prime numbers up to 'self'
|
161
|
+
|
162
|
+
# Create list with prime numbers up to 'self'
|
159
163
|
def prime_numbers
|
160
164
|
s = (0..self).to_a
|
161
165
|
s[0] = s[1] = nil
|
@@ -165,16 +169,11 @@ module Numbers
|
|
165
169
|
(p*p).step(self, p) { |m| s[m] = nil }
|
166
170
|
end
|
167
171
|
s.compact
|
168
|
-
end
|
169
|
-
|
172
|
+
end
|
173
|
+
|
170
174
|
end
|
171
175
|
|
172
176
|
|
173
|
-
Fixnum.class_eval do
|
174
|
-
def nan?
|
175
|
-
self.to_f.nan?
|
176
|
-
end
|
177
|
-
end
|
178
177
|
|
179
178
|
end
|
180
179
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: friendly_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Eck
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -72,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
72
|
version: '0'
|
73
73
|
requirements: []
|
74
74
|
rubyforge_project:
|
75
|
-
rubygems_version: 2.
|
75
|
+
rubygems_version: 2.4.8
|
76
76
|
signing_key:
|
77
77
|
specification_version: 4
|
78
78
|
summary: Collection of useful features for Ruby/Rails Classes
|