friendly_extensions 0.3 → 0.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 549d76483bac6763bd9b5944f46fbc84708ce6b7
4
- data.tar.gz: 0f95a6b71c60193f91b9aa42a5e8696db6b1831a
3
+ metadata.gz: e99c8cea01414ebad5d0899113c89acd88f4f8f7
4
+ data.tar.gz: ec0ebec211bccb79e4fdfbc61a3c5eb7bbc0eb06
5
5
  SHA512:
6
- metadata.gz: d1478abd77992536bf1a66a384bc1bb03d98062eaec7e203011ae2df232936dc28976c8e356d872458ac3727f7885645940220c5c9c8ff49c08c3fd898c22556
7
- data.tar.gz: 843ed4538fb08caed1f48e21e043d0b3d10751d93b11dd2ddbee674477e3de63d03b4c2fefe233f673f19a6f9bd8d82aa49e2121476e5bdef17cc51d84c011a4
6
+ metadata.gz: faead26916545e69c8f06488e35939d5d95fc733e52b71566b89a1e87521f869c4bd9c79593868f564361e02c8dd7d29f6571a4f755ff3f45d70e6d7fe1e4832
7
+ data.tar.gz: 189f363a97c30331d639144238d34b7af2e1733276f4c744032aacb02d25edcf21345989f3e204d11d227f48ffd5fc4d7522ec6b0e4a354b69143923218336b7
File without changes
File without changes
File without changes
File without changes
@@ -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
- module InstanceMethods # any method placed here will apply to instaces, like @hickwall
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
- str[1].size > 2 ? str[1] = str[1][0..1] : nil
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: '0.3'
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: 2018-04-27 00:00:00.000000000 Z
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.12
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