friendly_extensions 0.1 → 0.2
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.
- checksums.yaml +4 -4
- data/app/helpers/friends_labeled_form_helper.rb +14 -9
- metadata +2 -7
- data/config/initializers/values.rb +0 -24
- data/test/array_test.rb.orig +0 -221
- data/test/numeric_test.rb.orig +0 -94
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0b58b59a5540b798b4d2d975791ec31792a8789
|
4
|
+
data.tar.gz: b61194d062b60cf1fdd55643f1870656d1611bd6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d36a9cb3cd9fc84e89bd20d6ea6deaff1567e1cf464128dfc2bd9ead7632c62a63880d8b644416ad64f78d8f2d912e2e22f9e16e06369daebda0fd6642a4d1b9
|
7
|
+
data.tar.gz: e0535c4f3535208d204d40295981e6d9d4e3a564c1a3d355f9de5071b0e4de023a4285dd0d5054b0bc0e97f7682b2ff398cd6c9dda607836550d0637f66b3b0c
|
@@ -14,15 +14,20 @@ module FriendsLabeledFormHelper
|
|
14
14
|
|
15
15
|
if options[:errors]
|
16
16
|
label_text << tooltip_box(options[:errors].to_text)
|
17
|
-
elsif
|
18
|
-
|
19
|
-
if
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
17
|
+
elsif !options[:hide_tooltip] == true
|
18
|
+
# check if tooltip is given by options
|
19
|
+
if options[:tooltip].present?
|
20
|
+
label_text << tooltip_box(options[:tooltip])
|
21
|
+
elsif #look for tooltips for field in locale
|
22
|
+
i18n_str = "form_tooltips.#{object_name}.#{method}"
|
23
|
+
|
24
|
+
tt = begin
|
25
|
+
I18n.t(i18n_str)
|
26
|
+
rescue
|
27
|
+
i18n_str
|
28
|
+
end
|
29
|
+
|
30
|
+
label_text << tooltip_box(tt)
|
26
31
|
end
|
27
32
|
end
|
28
33
|
|
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.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Eck
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -34,7 +34,6 @@ files:
|
|
34
34
|
- app/helpers/friends_forms_helper.rb
|
35
35
|
- app/helpers/friends_labeled_form_helper.rb
|
36
36
|
- app/models/friends_label.rb
|
37
|
-
- config/initializers/values.rb
|
38
37
|
- config/locales/friendly_extensions.de.yml
|
39
38
|
- config/locales/friendly_extensions.en.yml
|
40
39
|
- db/migrate/001_drop_friends_labels.rb
|
@@ -52,11 +51,9 @@ files:
|
|
52
51
|
- lib/string_and_more.rb
|
53
52
|
- lib/tasks/friendly_extentions.rake
|
54
53
|
- test/array_test.rb
|
55
|
-
- test/array_test.rb.orig
|
56
54
|
- test/dummy_class.rb
|
57
55
|
- test/hash_test.rb
|
58
56
|
- test/numeric_test.rb
|
59
|
-
- test/numeric_test.rb.orig
|
60
57
|
- test/string_test.rb
|
61
58
|
homepage: https://github.com/florianeck/rails_friendly_extensions
|
62
59
|
licenses: []
|
@@ -83,10 +80,8 @@ specification_version: 4
|
|
83
80
|
summary: Collection of useful features for Ruby/Rails Classes
|
84
81
|
test_files:
|
85
82
|
- test/array_test.rb
|
86
|
-
- test/array_test.rb.orig
|
87
83
|
- test/dummy_class.rb
|
88
84
|
- test/hash_test.rb
|
89
85
|
- test/numeric_test.rb
|
90
|
-
- test/numeric_test.rb.orig
|
91
86
|
- test/string_test.rb
|
92
87
|
has_rdoc:
|
@@ -1,24 +0,0 @@
|
|
1
|
-
states = [
|
2
|
-
"Baden-Württemberg" ,
|
3
|
-
"Bayern" ,
|
4
|
-
"Berlin " ,
|
5
|
-
"Brandenburg" ,
|
6
|
-
"Bremen " ,
|
7
|
-
"Hamburg " ,
|
8
|
-
"Hessen" ,
|
9
|
-
"Mecklenburg-Vorpommern",
|
10
|
-
"Niedersachsen" ,
|
11
|
-
"Nordrhein-Westfalen" ,
|
12
|
-
"Rheinland-Pfalz" ,
|
13
|
-
"Saarland" ,
|
14
|
-
"Sachsen" ,
|
15
|
-
"Sachsen-Anhalt" ,
|
16
|
-
"Schleswig-Holstein" ,
|
17
|
-
"Thüringen"
|
18
|
-
]
|
19
|
-
|
20
|
-
GERMAN_STATES = states.map {|s| [s, states.index(s)+1]}
|
21
|
-
german_states_hash = {}
|
22
|
-
GERMAN_STATES.each {|s| german_states_hash.merge!(s[1] => s[0])}
|
23
|
-
|
24
|
-
GERMAN_STATES_HASH = german_states_hash
|
data/test/array_test.rb.orig
DELETED
@@ -1,221 +0,0 @@
|
|
1
|
-
require "test/unit"
|
2
|
-
require "array"
|
3
|
-
require "dummy_class"
|
4
|
-
|
5
|
-
class ArrayTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
#== Tests for .sum
|
8
|
-
def test_array_should_sum
|
9
|
-
assert_equal [1,2].sum, 3
|
10
|
-
end
|
11
|
-
|
12
|
-
#== Tests for .avg
|
13
|
-
def test_array_avg_with_numbers
|
14
|
-
test_array = [4,5]
|
15
|
-
|
16
|
-
assert_equal test_array.avg, 4.5
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_array_avg_with_attributes
|
20
|
-
test_array = []
|
21
|
-
test_array << DummyClass.new(:number => 4)
|
22
|
-
test_array << DummyClass.new(:number => 5)
|
23
|
-
|
24
|
-
assert_equal test_array.avg(:number), 4.5
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_array_avg_should_no_break_with_nil_and_emtpy
|
28
|
-
assert_equal [3,nil].avg, 3
|
29
|
-
assert_equal [].avg, 0
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
#== Tests for .array_to_hash
|
34
|
-
def test_array_should_make_to_hash
|
35
|
-
assert_equal [1,2].array_to_hash(""), {1 => "", 2 => ""}
|
36
|
-
assert_equal ["A","B"].array_to_hash(1), {"A" => 1, "B" => 1}
|
37
|
-
assert_equal ["A",nil].array_to_hash(1), {"A" => 1}
|
38
|
-
end
|
39
|
-
|
40
|
-
#== Tests for .to_structured_hash
|
41
|
-
def test_array_should_get_structured_with_symbol_and_nested_string
|
42
|
-
|
43
|
-
# Create Test Datas
|
44
|
-
test_data_row = []
|
45
|
-
test_data_row << DummyClass.new(:sec_id => 1, :name => "bla-1")
|
46
|
-
test_data_row << DummyClass.new(:sec_id => 1, :name => "bla-2")
|
47
|
-
test_data_row << DummyClass.new(:sec_id => 1, :name => "bla-3")
|
48
|
-
|
49
|
-
test_data_row << DummyClass.new(:sec_id => 2, :name => "blub-1")
|
50
|
-
test_data_row << DummyClass.new(:sec_id => 2, :name => "blub-2")
|
51
|
-
|
52
|
-
test_data_hash_sym = test_data_row.to_structured_hash(:sec_id)
|
53
|
-
test_data_hash_str = test_data_row.to_structured_hash("return_self.sec_id")
|
54
|
-
|
55
|
-
# Assertions
|
56
|
-
assert_equal test_data_hash_sym.keys.size, 2
|
57
|
-
assert_equal test_data_hash_sym[1].size, 3
|
58
|
-
assert_equal test_data_hash_sym[2].size, 2
|
59
|
-
|
60
|
-
assert_equal test_data_hash_sym, test_data_hash_str
|
61
|
-
end
|
62
|
-
|
63
|
-
#== Tests for .sum_with_attribute
|
64
|
-
def test_array_should_do_sum_with_attributes
|
65
|
-
|
66
|
-
test_array = []
|
67
|
-
test_array << DummyClass.new(:number => 4)
|
68
|
-
test_array << DummyClass.new(:number => 5)
|
69
|
-
|
70
|
-
# Using symbol
|
71
|
-
assert_equal test_array.sum_with_attribute(:number), 9
|
72
|
-
|
73
|
-
# Using nested string
|
74
|
-
assert_equal test_array.sum_with_attribute("return_self.number"), 9
|
75
|
-
|
76
|
-
# Using symbol with options
|
77
|
-
assert_equal test_array.sum_with_attribute(:get_number, :double => true), 18
|
78
|
-
|
79
|
-
# Using nested string with options
|
80
|
-
assert_equal test_array.sum_with_attribute("return_self.get_number", :double => true), 18
|
81
|
-
end
|
82
|
-
|
83
|
-
#== Tests for .count_for
|
84
|
-
def test_array_should_count_for_items
|
85
|
-
a1 = [1,2,3]
|
86
|
-
|
87
|
-
assert_equal a1.count_for(1), 1
|
88
|
-
|
89
|
-
a2 = %w(a a b c)
|
90
|
-
assert_equal a2.count_for("a"), 2
|
91
|
-
|
92
|
-
a3 = %w(a b c)
|
93
|
-
assert_equal a3.count_for("x"), 0
|
94
|
-
|
95
|
-
a4 = [1,:a, nil]
|
96
|
-
assert_equal a4.count_for(nil), 1
|
97
|
-
end
|
98
|
-
|
99
|
-
#== Tests for .next
|
100
|
-
def test_get_next_array_item_without_cycle
|
101
|
-
a = [1,2,3]
|
102
|
-
assert_equal a.next(2), 3
|
103
|
-
assert_equal a.next(3), 3
|
104
|
-
assert_equal a.next(4), 4
|
105
|
-
|
106
|
-
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_get_next_array_item_with_cycle
|
110
|
-
a = [1,2,3]
|
111
|
-
assert_equal a.next(3, :cycle => true), 1
|
112
|
-
assert_equal a.next(1, :cycle => true), 2
|
113
|
-
end
|
114
|
-
|
115
|
-
#== Tests for .isec
|
116
|
-
def test_array_must_isec_with_array
|
117
|
-
assert_raises ArgumentError do
|
118
|
-
[1,2,3].isec(3)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_array_isec
|
123
|
-
a1 = %w(a b c d)
|
124
|
-
a2 = %w(c d e f)
|
125
|
-
a3 = %w(a f x y)
|
126
|
-
a4 = %w(1 2 3 4)
|
127
|
-
|
128
|
-
assert_equal a1.isec(a2), %w(c d)
|
129
|
-
assert_equal (a1+a2).isec(a3), %w(a f)
|
130
|
-
assert_equal a3.isec(a4), []
|
131
|
-
end
|
132
|
-
|
133
|
-
#== Tests for .except
|
134
|
-
def test_array_except
|
135
|
-
a = [1,2,3, "a", "b"]
|
136
|
-
assert_equal a.except(1), [2,3, "a", "b"]
|
137
|
-
assert_equal a.except(1,2), [3, "a", "b"]
|
138
|
-
assert_equal a.except(1,"a"), [2,3, "b"]
|
139
|
-
end
|
140
|
-
|
141
|
-
#== Tests for .seperate
|
142
|
-
def test_array_seperation
|
143
|
-
{4 => (1..10).to_a, 25 => (1..100).to_a}.each do |n, array|
|
144
|
-
|
145
|
-
sep_array = array.seperate(n)
|
146
|
-
|
147
|
-
assert_equal sep_array.size, n
|
148
|
-
assert_equal sep_array.flatten, array
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
def test_array_should_seperate__arrays_correctly
|
153
|
-
# Fix for:
|
154
|
-
# [[1, "a"], [2, "b"], [3, "c"]].seperate(2).last
|
155
|
-
# => [[2, "b"], [[3, "c"]]] - Last Array is in an other array
|
156
|
-
|
157
|
-
assert_equal [[1, "a"], [2, "b"], [3, "c"]].seperate(2).last.last, [3,"c"]
|
158
|
-
assert_equal [[1, "a"], [2, "b"], [3, "c"], [4, "d"]].seperate(2).last.last, [4,"d"]
|
159
|
-
|
160
|
-
end
|
161
|
-
|
162
|
-
#== Tests for .stack
|
163
|
-
def test_array_stack
|
164
|
-
{4 => (1..10).to_a, 25 => (1..100).to_a}.each do |n, array|
|
165
|
-
|
166
|
-
sep_array = array.stack(n)
|
167
|
-
|
168
|
-
assert_equal sep_array.first.size, n
|
169
|
-
assert_equal sep_array.flatten, array
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
#== Tests for .to_sql
|
174
|
-
def test_array_to_sql
|
175
|
-
# Empty array is NULL
|
176
|
-
assert_equal [].to_sql, "(NULL)"
|
177
|
-
|
178
|
-
# Numbers should be unquoted
|
179
|
-
a = [1,2,4.5]
|
180
|
-
assert_no_match Regexp.new("'"), a.to_sql
|
181
|
-
assert_equal a.to_sql, "(1,2,4.5)"
|
182
|
-
|
183
|
-
<<<<<<< HEAD
|
184
|
-
# All others should be quoted
|
185
|
-
a = ["a", :b]
|
186
|
-
assert_match Regexp.new("'"), a.to_sql
|
187
|
-
assert_equal a.to_sql, "('a','b')"
|
188
|
-
end
|
189
|
-
|
190
|
-
#== Test interpolation
|
191
|
-
def test_array_should_interpolate
|
192
|
-
|
193
|
-
# First should not fail
|
194
|
-
assert_equal [nil,1,2].interpolate(nil), [0,1,2]
|
195
|
-
# These fail:
|
196
|
-
# assert_equal [nil, nil,1,2].interpolate(nil), [-1, 0,1,2]
|
197
|
-
|
198
|
-
|
199
|
-
# Last should not fail
|
200
|
-
assert_equal [1,2,3], [1,2,nil].interpolate(nil).map {|x| x.to_i }
|
201
|
-
# These fail:
|
202
|
-
# assert_equal [1,2,3,4], [1,2,nil,nil].interpolate(nil).map {|x| x.to_i }
|
203
|
-
|
204
|
-
# In The middle
|
205
|
-
assert_equal [1,2,3,4,5], [1,2,3,nil,5].interpolate(nil).map {|x| x.to_i }
|
206
|
-
assert_equal [1,2,3,4,5], [1,2,nil,nil,5].interpolate(nil).map {|x| x.to_i }
|
207
|
-
assert_equal [5,10,15,20,25], [5,nil,15,nil,25].interpolate(nil).map {|x| x.to_i }
|
208
|
-
assert_equal [5,10,15,20,25,30], [5,nil,15,nil,nil,30].interpolate(nil).map {|x| x.to_i }
|
209
|
-
end
|
210
|
-
|
211
|
-
=======
|
212
|
-
# All others should be unquoted
|
213
|
-
a = ["a", :b]
|
214
|
-
assert_match Regexp.new("'"), a.to_sql
|
215
|
-
assert_equal a.to_sql, "('a','b')"
|
216
|
-
end
|
217
|
-
>>>>>>> ad58e345c5de2638e34e44d69bb19b0ebebcd41e
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
end
|
data/test/numeric_test.rb.orig
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
require "test/unit"
|
2
|
-
require "numbers"
|
3
|
-
|
4
|
-
|
5
|
-
class NumericTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
|
8
|
-
def test_number_to_euro
|
9
|
-
#assert_equal 0.29.to_euro, "0,29"
|
10
|
-
end
|
11
|
-
|
12
|
-
# Test Math Functions
|
13
|
-
def test_math_infla_defla
|
14
|
-
|
15
|
-
[2, 3.3].each do |f|
|
16
|
-
[40,250].each do |n|
|
17
|
-
i = 500
|
18
|
-
r_inf = r_def = i
|
19
|
-
|
20
|
-
n.times do |i|
|
21
|
-
r_inf = r_inf*(1+f/100.0)
|
22
|
-
r_def = r_def*(1-f/100.0)
|
23
|
-
end
|
24
|
-
|
25
|
-
assert_equal i.infla(n,f).round(5), r_inf.round(5)
|
26
|
-
assert_equal i.defla(n,f).round(5), r_def.round(5)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_number_should_get_closest
|
33
|
-
# Test for wrong limit mode:
|
34
|
-
assert_raise ArgumentError do
|
35
|
-
1.get_closest([3,4], :zonk)
|
36
|
-
end
|
37
|
-
|
38
|
-
# Check to find closest
|
39
|
-
assert_equal 2.get_closest([0,3,4], :ceil), 3
|
40
|
-
assert_equal 2.get_closest([0,3,4], :floor), 3
|
41
|
-
assert_equal -2.88.get_closest([0,3,4], :floor), 0
|
42
|
-
|
43
|
-
# Check to find closest with :floor
|
44
|
-
assert_equal 1.get_closest([0,2], :floor), 0
|
45
|
-
assert_equal 5.5.get_closest([4.5,6.5], :floor), 4.5
|
46
|
-
|
47
|
-
# Check to find closest with :ceil
|
48
|
-
assert_equal 1.get_closest([0,2], :ceil), 2
|
49
|
-
assert_equal 5.5.get_closest([4.5,6.5], :ceil), 6.5
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
def test_numbers_min_and_max
|
55
|
-
assert_equal 1, 1.min(3)
|
56
|
-
assert_equal 3, 1.max(3)
|
57
|
-
assert_equal 2, 2.min_max(1,3)
|
58
|
-
assert_equal 1, -1.min_max(1,3)
|
59
|
-
assert_equal 3, 4.min_max(1,3)
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_float_dividor
|
63
|
-
assert !1.fdiv(1).is_a?(Integer)
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_to_q_faktor
|
67
|
-
assert_equal 2.to_q, 1.02
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_time_should_be_calc_correct
|
71
|
-
assert_equal 23.to_time, "00:00:23"
|
72
|
-
assert_equal 64.to_time, "00:01:04"
|
73
|
-
|
74
|
-
assert_equal 17.to_time(:discard_hour => true), "00:17"
|
75
|
-
assert_equal 73.to_time(:discard_hour => true), "01:13"
|
76
|
-
|
77
|
-
assert_equal 3672.to_time, "01:01:12"
|
78
|
-
<<<<<<< HEAD
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_prime_factors
|
82
|
-
|
83
|
-
[16,234,4568,34950,183649].each do |nr|
|
84
|
-
primes = nr.prime_factors
|
85
|
-
puts "#{nr} => #{primes.inspect}"
|
86
|
-
assert_equal nr, eval(primes.join("*"))
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
90
|
-
=======
|
91
|
-
end
|
92
|
-
>>>>>>> ad58e345c5de2638e34e44d69bb19b0ebebcd41e
|
93
|
-
|
94
|
-
end
|