store_as_int 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/store_as_int/base.rb +41 -5
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6b72bc34f16042d91c14899ff1aedbdfbec14bc8e4c70f79d6e9511afccae28
4
- data.tar.gz: 432f5f3458d0315d129e58c2c3f9f7d1794e8d2bf3b13238e4de36b53ff8195a
3
+ metadata.gz: 6b0c0f4315719d04045325c81ea7948ee59ad82407c94d5bfa94976facdffb69
4
+ data.tar.gz: ed63ac7ed1e99d27b11b694852cbe1e3442fc6ae11b5b6f5b0447600c2079e8e
5
5
  SHA512:
6
- metadata.gz: 4ea8dac641d4b63a2b14b97459f004a458b1e6df0e2607c29db5bba2a6daca31e15192bbf6c6ad941f072a3ad59ee709a0b84124e765f8de1c73af72fe22d896
7
- data.tar.gz: f3cd3dd48ee061f9c6ad92947989d582a6b61bdb8d6aa63fd25b927732dfa1609d685045a21b50da2847be37404ce63951a13fd03affd03ea442a6aa7248d189
6
+ metadata.gz: 5a5f941ef7473bc8fee050fbaf9f0daa1e323ab5b3437f154fc8cd7f6196816c587519065d7e1adbefb858041135932d95c1042881232d1c9cd6a63327b2cdba
7
+ data.tar.gz: 03be66cf00bf45df03419f6e5bbc7d1f66ac91d1793a5a373d09a7c73342536690da73b1de7fa1f7dffc66714f02ac1614d8c0bd4c9868085cb549ce3278d600
@@ -33,10 +33,6 @@ module StoreAsInt
33
33
  )
34
34
  end
35
35
 
36
- def self.matcher
37
- /^(\-|\+)?(?:#{sym.to_s.size > 0 ? Regexp.quote(sym.to_s) : '[^0-9]'}*)([0-9]+)(\.[0-9]+)?$/
38
- end
39
-
40
36
  def self.accuracy
41
37
  self::ACCURACY || 0
42
38
  end
@@ -49,6 +45,46 @@ module StoreAsInt
49
45
  self::DECIMALS
50
46
  end
51
47
 
48
+ def self.hash_without_keys(h, keys, indifferent = false)
49
+ n = h.dup
50
+ if indifferent
51
+ new_keys = keys.dup
52
+ new_keys.each do |k|
53
+ keys << k.to_sym
54
+ keys << k.to_s
55
+ end
56
+ kys = keys.uniq
57
+ end
58
+ keys.each do |k|
59
+ n.delete(k)
60
+ end
61
+ n
62
+ end
63
+
64
+ def self.json_create(o)
65
+ if o.is_a?(Hash)
66
+ n = {}
67
+ for k, v in o
68
+ n[k.to_sym] = v
69
+ end
70
+ created = new((n[:value] || n[:int] || n[:decimal] || n[:float] || n[:str]), (n[:sym] || nil))
71
+
72
+ hash_without_keys(o, %w(decimal float int json_class str str_pretty value), true).each do |k, v|
73
+ k = k.dup
74
+ if created.respond_to?(k, true) || created.respond_to?(k.to_s.sub!('str_', ''))
75
+ created.instance_variable_set("@#{k}", v)
76
+ end
77
+ end
78
+ created
79
+ else
80
+ new(o)
81
+ end
82
+ end
83
+
84
+ def self.matcher
85
+ /^(\-|\+)?(?:#{sym.to_s.size > 0 ? Regexp.quote(sym.to_s) : '[^0-9]'}*)([0-9]+)(\.[0-9]+)?$/
86
+ end
87
+
52
88
  def self.sym
53
89
  self::SYM
54
90
  end
@@ -193,7 +229,6 @@ module StoreAsInt
193
229
  @operators ||= self.class.operators.dup
194
230
  end
195
231
 
196
-
197
232
  def sym
198
233
  @sym ||= self.class.sym || ''
199
234
  end
@@ -218,6 +253,7 @@ module StoreAsInt
218
253
  decimals: decimals,
219
254
  float: to_f,
220
255
  int: to_i,
256
+ json_class: self.class,
221
257
  str: to_s,
222
258
  str_format: str_format,
223
259
  str_matcher: matcher,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: store_as_int
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sampson Crowley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-16 00:00:00.000000000 Z
11
+ date: 2018-06-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Seamlessly store different types of values (such as dollars) as integers
14
14
  email: sampsonsprojects@gmail.com
@@ -40,7 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
40
40
  version: '0'
41
41
  requirements: []
42
42
  rubyforge_project:
43
- rubygems_version: 2.7.6
43
+ rubygems_version: 2.7.7
44
44
  signing_key:
45
45
  specification_version: 4
46
46
  summary: Store values as integers for lossless calculations