friendly_extensions 0.3 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/helpers/friends_forms_helper.rb +0 -0
- data/app/helpers/friends_labeled_form_helper.rb +0 -0
- data/config/locales/friendly_extensions.de.yml +0 -0
- data/config/locales/friendly_extensions.en.yml +0 -0
- data/lib/friendly_extensions/engine.rb +0 -0
- data/lib/smart_currency.rb +30 -26
- data/lib/tasks/friendly_extentions.rake +0 -0
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e99c8cea01414ebad5d0899113c89acd88f4f8f7
|
4
|
+
data.tar.gz: ec0ebec211bccb79e4fdfbc61a3c5eb7bbc0eb06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: faead26916545e69c8f06488e35939d5d95fc733e52b71566b89a1e87521f869c4bd9c79593868f564361e02c8dd7d29f6571a4f755ff3f45d70e6d7fe1e4832
|
7
|
+
data.tar.gz: 189f363a97c30331d639144238d34b7af2e1733276f4c744032aacb02d25edcf21345989f3e204d11d227f48ffd5fc4d7522ec6b0e4a354b69143923218336b7
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/smart_currency.rb
CHANGED
@@ -1,46 +1,50 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
module SmartCurrency
|
3
|
-
|
3
|
+
|
4
4
|
def self.included(base)
|
5
5
|
base.extend ClassMethods
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
module ClassMethods
|
9
|
-
def smart_currency
|
9
|
+
def smart_currency(skip_on: [])
|
10
|
+
|
10
11
|
if !smart_currency? && table_exists?
|
11
12
|
include InstanceMethods
|
12
13
|
auto_attributes = []
|
14
|
+
|
13
15
|
self.skip_time_zone_conversion_for_attributes = []
|
14
|
-
|
16
|
+
|
15
17
|
self.send(:attr_accessor, :disable_smart_currency)
|
16
|
-
|
18
|
+
|
17
19
|
attributes = self.columns.select {|c| (c.type == :integer || c.type == :decimal) && !c.name.match("id") }
|
18
|
-
|
20
|
+
|
19
21
|
attributes.each do |a|
|
22
|
+
|
23
|
+
next if skip_on.include?(a.name.to_s.to_sym) || skip_on.include?(a.name.to_s)
|
20
24
|
define_method("#{a.name}=") do |val|
|
21
25
|
self[a.name.to_sym] = (disable_smart_currency == true ? val : currency_to_db(val))
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
26
30
|
end
|
27
|
-
|
31
|
+
|
28
32
|
def smart_currency?
|
29
33
|
self.included_modules.include?(InstanceMethods)
|
30
34
|
end
|
31
|
-
|
32
|
-
end
|
33
35
|
|
34
|
-
|
35
|
-
|
36
|
+
end
|
37
|
+
|
38
|
+
module InstanceMethods
|
39
|
+
|
36
40
|
def currency_to_db(string)
|
37
|
-
if string.is_a?(String)
|
41
|
+
if string.is_a?(String)
|
38
42
|
return (string.gsub(/\./, '').gsub(/,/, '.')).to_f
|
39
43
|
elsif string.nil?
|
40
44
|
return 0
|
41
|
-
else
|
45
|
+
else
|
42
46
|
return string
|
43
|
-
end
|
47
|
+
end
|
44
48
|
end
|
45
49
|
|
46
50
|
def currency_to_view(decimal)
|
@@ -53,17 +57,17 @@ module SmartCurrency
|
|
53
57
|
if str[0].size == 5 || str[0].size == 6
|
54
58
|
str[0].gsub!(/\B([0-9]{3})\b/,'.\1')
|
55
59
|
elsif str[0].size > 7
|
56
|
-
str[0].gsub!(/([0-9]{3})\b/,'.\1').gsub!(/([0-9]{3}\.)/, '.\1')
|
60
|
+
str[0].gsub!(/([0-9]{3})\b/,'.\1').gsub!(/([0-9]{3}\.)/, '.\1')
|
57
61
|
else
|
58
|
-
str[0].gsub!(/\B([0-9]{3})/,'.\1')
|
62
|
+
str[0].gsub!(/\B([0-9]{3})/,'.\1')
|
59
63
|
end
|
60
|
-
|
61
|
-
return (str[0] + "," + str[1]).to_s
|
62
|
-
else
|
64
|
+
|
65
|
+
return (str[0] + "," + str[1]).to_s
|
66
|
+
else
|
63
67
|
return "keine Angabe"
|
64
|
-
end
|
68
|
+
end
|
65
69
|
end
|
66
|
-
|
70
|
+
|
67
71
|
end
|
68
|
-
|
72
|
+
|
69
73
|
end
|
File without changes
|
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:
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Eck
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -54,7 +54,8 @@ files:
|
|
54
54
|
- test/numeric_test.rb
|
55
55
|
- test/string_test.rb
|
56
56
|
homepage: https://github.com/florianeck/rails_friendly_extensions
|
57
|
-
licenses:
|
57
|
+
licenses:
|
58
|
+
- MIT
|
58
59
|
metadata: {}
|
59
60
|
post_install_message:
|
60
61
|
rdoc_options: []
|
@@ -72,13 +73,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
73
|
version: '0'
|
73
74
|
requirements: []
|
74
75
|
rubyforge_project:
|
75
|
-
rubygems_version: 2.6.
|
76
|
+
rubygems_version: 2.6.14
|
76
77
|
signing_key:
|
77
78
|
specification_version: 4
|
78
79
|
summary: Collection of useful features for Ruby/Rails Classes
|
79
80
|
test_files:
|
80
|
-
- test/array_test.rb
|
81
81
|
- test/dummy_class.rb
|
82
|
+
- test/array_test.rb
|
82
83
|
- test/hash_test.rb
|
83
|
-
- test/numeric_test.rb
|
84
84
|
- test/string_test.rb
|
85
|
+
- test/numeric_test.rb
|