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.
- checksums.yaml +4 -4
- data/lib/store_as_int/base.rb +41 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b0c0f4315719d04045325c81ea7948ee59ad82407c94d5bfa94976facdffb69
|
4
|
+
data.tar.gz: ed63ac7ed1e99d27b11b694852cbe1e3442fc6ae11b5b6f5b0447600c2079e8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a5f941ef7473bc8fee050fbaf9f0daa1e323ab5b3437f154fc8cd7f6196816c587519065d7e1adbefb858041135932d95c1042881232d1c9cd6a63327b2cdba
|
7
|
+
data.tar.gz: 03be66cf00bf45df03419f6e5bbc7d1f66ac91d1793a5a373d09a7c73342536690da73b1de7fa1f7dffc66714f02ac1614d8c0bd4c9868085cb549ce3278d600
|
data/lib/store_as_int/base.rb
CHANGED
@@ -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.
|
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-
|
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.
|
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
|