friendly_extensions 0.0.8 → 0.0.61

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/test/array_test.rb CHANGED
@@ -24,7 +24,7 @@ class ArrayTest < Test::Unit::TestCase
24
24
  assert_equal test_array.avg(:number), 4.5
25
25
  end
26
26
 
27
- def test_array_avg_should_not_break_with_nil_and_emtpy
27
+ def test_array_avg_should_no_break_with_nil_and_emtpy
28
28
  assert_equal [3,nil].avg, 3
29
29
  assert_equal [].avg, 0
30
30
  end
@@ -180,33 +180,11 @@ class ArrayTest < Test::Unit::TestCase
180
180
  assert_no_match Regexp.new("'"), a.to_sql
181
181
  assert_equal a.to_sql, "(1,2,4.5)"
182
182
 
183
- # All others should be quoted
183
+ # All others should be unquoted
184
184
  a = ["a", :b]
185
185
  assert_match Regexp.new("'"), a.to_sql
186
186
  assert_equal a.to_sql, "('a','b')"
187
- end
188
-
189
- #== Test interpolation
190
- def test_array_should_interpolate
191
-
192
- # First should not fail
193
- assert_equal [nil,1,2].interpolate(nil), [0,1,2]
194
- # These fail:
195
- # assert_equal [nil, nil,1,2].interpolate(nil), [-1, 0,1,2]
196
-
197
-
198
- # Last should not fail
199
- assert_equal [1,2,3], [1,2,nil].interpolate(nil).map {|x| x.to_i }
200
- # These fail:
201
- # assert_equal [1,2,3,4], [1,2,nil,nil].interpolate(nil).map {|x| x.to_i }
202
-
203
- # In The middle
204
- assert_equal [1,2,3,4,5], [1,2,3,nil,5].interpolate(nil).map {|x| x.to_i }
205
- assert_equal [1,2,3,4,5], [1,2,nil,nil,5].interpolate(nil).map {|x| x.to_i }
206
- assert_equal [5,10,15,20,25], [5,nil,15,nil,25].interpolate(nil).map {|x| x.to_i }
207
- assert_equal [5,10,15,20,25,30], [5,nil,15,nil,nil,30].interpolate(nil).map {|x| x.to_i }
208
- end
209
-
187
+ end
210
188
 
211
189
 
212
190
 
data/test/numeric_test.rb CHANGED
@@ -9,10 +9,6 @@ class NumericTest < Test::Unit::TestCase
9
9
  #assert_equal 0.29.to_euro, "0,29"
10
10
  end
11
11
 
12
- def test_number_should_convert_to_array
13
- assert_equal 1.to_a, [1]
14
- end
15
-
16
12
  # Test Math Functions
17
13
  def test_math_infla_defla
18
14
 
@@ -79,16 +75,6 @@ class NumericTest < Test::Unit::TestCase
79
75
  assert_equal 73.to_time(:discard_hour => true), "01:13"
80
76
 
81
77
  assert_equal 3672.to_time, "01:01:12"
82
- end
83
-
84
- def test_prime_factors
85
-
86
- [16,234,4568,34950,183649].each do |nr|
87
- primes = nr.prime_factors
88
- puts "#{nr} => #{primes.inspect}"
89
- assert_equal nr, eval(primes.join("*"))
90
- end
91
-
92
- end
78
+ end
93
79
 
94
80
  end
metadata CHANGED
@@ -1,59 +1,51 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: friendly_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.61
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-04-22 00:00:00.000000000 Z
11
+ date: 2014-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 3.2.9
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 3.2.9
27
27
  description: Adds serveral cool features to your Ruby classes. Includes new features
28
28
  for Array, String, Hash, Numeric, Date/Datetime and some more.
29
- email: florian.eck@el-digital.de
29
+ email: it-support@friends-systems.de
30
30
  executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
- - app/helpers/friends_forms_helper.rb
35
- - app/helpers/friends_labeled_form_helper.rb
36
- - app/models/friends_label.rb
37
- - config/initializers/values.rb
38
- - db/migrate/20140326005600_create_labels.rb
39
34
  - lib/alphanumeric.rb
40
35
  - lib/array.rb
41
36
  - lib/boolean.rb
42
37
  - lib/chars_2_remove.rb
43
38
  - lib/date_n_time.rb
44
39
  - lib/friendly_extensions.rb
45
- - lib/friendly_extensions/engine.rb
46
40
  - lib/hash.rb
47
41
  - lib/nil_class.rb
48
42
  - lib/numbers.rb
49
43
  - lib/smart_currency.rb
50
44
  - lib/string_and_more.rb
51
45
  - test/array_test.rb
52
- - test/array_test.rb.orig
53
46
  - test/dummy_class.rb
54
47
  - test/hash_test.rb
55
48
  - test/numeric_test.rb
56
- - test/numeric_test.rb.orig
57
49
  - test/string_test.rb
58
50
  homepage: https://github.com/florianeck/rails_friendly_extensions
59
51
  licenses: []
@@ -74,16 +66,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
66
  version: '0'
75
67
  requirements: []
76
68
  rubyforge_project:
77
- rubygems_version: 2.4.3
69
+ rubygems_version: 2.2.1
78
70
  signing_key:
79
71
  specification_version: 4
80
72
  summary: Collection of useful features for Ruby/Rails Classes
81
73
  test_files:
82
74
  - test/array_test.rb
83
- - test/array_test.rb.orig
84
75
  - test/dummy_class.rb
85
76
  - test/hash_test.rb
86
77
  - test/numeric_test.rb
87
- - test/numeric_test.rb.orig
88
78
  - test/string_test.rb
89
- has_rdoc:
@@ -1,27 +0,0 @@
1
- module FriendsFormsHelper
2
-
3
- def fieldset(title, options = {}, &block)
4
- if options[:if].nil? || options[:if] == true
5
- data_string = " "
6
- if options[:data]
7
- options[:data].each {|d,v| data_string << "#{d}='v' "}
8
- end
9
- concat raw("<fieldset id='#{options[:id]}' #{data_string} class='shadow #{options[:mainclass]}' #{("style='height: %spx'" % options[:height]) if options[:height]} style='#{options[:mainstyle]}'>")
10
- concat raw("<legend class='#{options[:class]}' style='#{options[:style]}'>#{title}</legend><div class='fieldset-content'>")
11
- yield
12
- concat raw("</div></fieldset>")
13
- end
14
- end
15
-
16
- def tooltip_box(tooltip)
17
- "<span class='label-tooltip' title='#{tooltip}'>&nbsp;</span>".html_safe
18
- end
19
-
20
- def tooltip_content_box(name, options = {}, &block)
21
- options[:default_class] ||= "icon-clue"
22
- html = "<div class='tooltip-box'><div class='tooltip-box-label #{options[:default_class]}'>"
23
- html << "#{name}<div class='tooltip-box-content #{options[:css]} box rounded shadow'>#{capture(&block)}</div></div></div>"
24
- concat(html.html_safe)
25
- end
26
-
27
- end
@@ -1,124 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- module FriendsLabeledFormHelper
3
-
4
- def self.included(arg)
5
- ActionView::Helpers::FormBuilder.send(:include, FriendsLabeledFormBuilder)
6
- end
7
-
8
- def label_tag_for(object_name, method, options = {})
9
- label_name = (options[:label].blank? ? method.to_label : options[:label])
10
-
11
- label_name += options[:append] unless options[:append].nil?
12
-
13
- label_text = "<span class='label-text'>#{label_name}</span>"
14
-
15
- if options[:errors]
16
- label_text << tooltip_box(options[:errors].to_text)
17
- elsif ((options[:label].blank? && options[:tooltip].blank?) || !options[:tooltip].blank?) && options[:tooltip] != false
18
- tooltip = (options[:tooltip] || method.to_label(:show_tooltip => true))
19
- if !tooltip.blank? && options[:hide_tooltip] != true
20
- # Setting Tooltip format for display in Browsertooltip
21
- # line breaks in unicode
22
- tooltip = tooltip.gsub(/\n|\<br(\ )?(\/)?\>/, "&#xA;")
23
- # single to double quotes
24
- tooltip = tooltip.gsub("'", '"')
25
- label_text << tooltip_box(tooltip)
26
- end
27
- end
28
-
29
-
30
- label_options = {}
31
- label_options.merge!(:class => options[:class]) unless options[:class].blank?
32
- label_options.merge!(:for => options[:for]) unless options[:for].blank?
33
- label_options.merge!(:id => options[:id]) unless options[:id].blank?
34
-
35
- return label(object_name, method, label_text.html_safe, label_options).html_safe
36
- end
37
-
38
- def labeled_text_field(object_name, method, options={})
39
-
40
- if options[:id]
41
- label_options = options.merge(:id => "label-#{options[:id]}")
42
- else
43
- label_options = options
44
- end
45
-
46
- html = label_tag_for(object_name, method, label_options)
47
- if options[:password] && options.delete(:password)
48
- html += password_field(object_name, method, options)
49
- else
50
- html += text_field(object_name, method, options)
51
- end
52
- return html.html_safe
53
- end
54
-
55
- def labeled_check_box(object_name, method, options={}, checked_value=1, unchecked_value=0)
56
- method = method.to_s.to_sym
57
- box_id = object_name.to_s+"_"+method.to_s
58
-
59
- html = "<div class='cf labeled-check-box'>"
60
- html += "<div class='checkbox-container'>#{check_box(object_name, method, options.merge!(:id => box_id), checked_value, unchecked_value)}</div>"
61
- html += "<div class='checkbox-label-container'>#{label_tag_for(object_name, method, :label => options[:label], :tooltip => options[:tooltip], :class => "checkbox-label", :for => box_id, :errors => options[:errors])}</div>"
62
- html += "</div>"
63
-
64
- return html.html_safe
65
- end
66
-
67
-
68
-
69
- def labeled_radio_button(object_name, method, value, options = {})
70
- options[:id] ||= "radio-#{method.to_s}-#{value.inspect}"
71
- options[:label] ||= method.to_label
72
- html = "<div class='cf labeled-radio-button'>"
73
- html << radio_button(object_name, method, value, options.except(:label, :errors))
74
- html << "&nbsp;"
75
- html << label_tag_for(object_name, method, {:label => options[:label], :for => options[:id]})
76
- html << "</div>"
77
- return raw(html)
78
- end
79
-
80
- end
81
-
82
- module FriendsLabeledFormBuilder
83
-
84
- def label_tag_for(method, options = {})
85
- @template.label_tag_for(@object_name, method, options)
86
- end
87
-
88
-
89
- def labeled_radio_button(method, value, options ={})
90
- options[:checked] = (object.send(method) == value) if options[:checked].nil?
91
-
92
- options[:class] ||= ""
93
- options[:class] << " error" if ((!object.errors[method.to_sym].empty? && !object.new_record?) rescue false )
94
- options[:errors] = ((object.errors[method.to_sym].empty? ? nil : object.errors[method.to_sym]) rescue false )
95
-
96
- @template.labeled_radio_button(@object_name, method, value, options)
97
- end
98
-
99
-
100
- def labeled_check_box(method, options = {}, checked_value=1, unchecked_value=0)
101
-
102
- options[:class] ||= ""
103
- options[:class] << " error" if ((!object.errors[method.to_sym].empty? && !object.new_record?) rescue false )
104
- options[:errors] = ((object.errors[method.to_sym].empty? ? nil : object.errors[method.to_sym]) rescue false )
105
-
106
- options[:checked] ||= ((object.send(method) rescue false) || options[:checked])
107
- @template.labeled_check_box(@object_name, method, options, checked_value, unchecked_value)
108
- end
109
-
110
-
111
- def labeled_text_field(method, options = {})
112
-
113
- options[:value] ||= (object.send(method) rescue nil )
114
- options[:class] ||= ""
115
- options[:class] << " error" if ((!object.errors[method.to_sym].empty? && !object.new_record?) rescue false )
116
-
117
- options[:errors] = ((object.errors[method.to_sym].empty? ? nil : object.errors[method.to_sym]) rescue false )
118
-
119
- @template.labeled_text_field(@object_name, method, options)
120
- end
121
-
122
- end
123
-
124
-
@@ -1,22 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- class FriendsLabel < ActiveRecord::Base
3
-
4
- validates_uniqueness_of :attribute_name
5
-
6
-
7
-
8
- labels = {}
9
-
10
- if self.table_exists?
11
- concept_labels = FriendsLabel.all
12
- concept_labels.each {|l| labels.merge!(l.attribute_name => {:label => l.label, :tooltip => l.tooltip, :docu_tooltip => l.tooltip_docu})}
13
- end
14
-
15
- LABELS = labels
16
-
17
-
18
- def is_unset?
19
- return (!(self.attribute_name == self.label)).to_s
20
- end
21
-
22
- end
@@ -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
@@ -1,13 +0,0 @@
1
- class CreateLabels < ActiveRecord::Migration
2
-
3
- def change
4
- create_table "friends_labels", :force => true do |t|
5
- t.string "attribute_name"
6
- t.string "label"
7
- t.text "tooltip"
8
- t.text "tooltip_docu"
9
- t.text "search_tags"
10
- end
11
- end
12
-
13
- end
@@ -1,10 +0,0 @@
1
- module FriendlyExtensions
2
- class Engine < Rails::Engine
3
- engine_name "friendly_extensions"
4
-
5
- initializer "friends.labeled_form_helper" do
6
- ActionView::Helpers::FormBuilder.send(:include, FriendsLabeledFormHelper)
7
- end
8
-
9
- end
10
- end
@@ -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