store_as_int 0.0.12 → 0.0.13

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/store_as_int/base.rb +26 -6
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22dbf2bdae8fc03aa6f324698da139fef527f583989ddf7665a0c93245858c55
4
- data.tar.gz: c8d9c7c5d64d21590f690838ad9d3b136459a5268e7399c90a50e101366cd4ec
3
+ metadata.gz: ac0aa2949e48139e5ab1607f3290b1084c9c7559ae24eb5700dea195bcc3b142
4
+ data.tar.gz: 507fb4a73ba8ab74261177eb08a9b386d10598b58c8440579d2f96dfb45b26d1
5
5
  SHA512:
6
- metadata.gz: 6cf32d9dfcad73cbe5b9c17306dd0c3ad25f7474d240051618d7fbbb1fb683accc301411d50113eb98505c11f937341a710b9fce6cbb73f83149ad9ca7893753
7
- data.tar.gz: 708f09372d3adcd06cc50d15b86e47529b5cca07481c7173a9d3e0b9ee4dc15decada51ffee7a08f074f33d97cc3133ee2d2efb441e0cb78e983ce7a7c334b56
6
+ metadata.gz: a247d53dcdfc04255edda57cda0630e9dae8e05806889d16156a53794213589548645c8ee92c645fc652a98d2e902901f84778892d7fa1bc14bdd9985aa20769
7
+ data.tar.gz: d25ca8ca14dd38a94db102e187350d02f4da96712d19738c779e75b00b25c690ca2cf16f7a09b31363b05cbbf45a854a8a7cbf6afaf3a175b8ef97d9ac3e6506
@@ -62,6 +62,10 @@ module StoreAsInt
62
62
  end
63
63
 
64
64
  # == Boolean Methods ======================================================
65
+ def duplicable?
66
+ true
67
+ end
68
+
65
69
  def is_a?(klass)
66
70
  kind_of?(klass)
67
71
  end
@@ -104,7 +108,7 @@ module StoreAsInt
104
108
 
105
109
  # == Instance Methods =====================================================
106
110
  def initialize(new_val = nil)
107
- return self.num = nil unless new_val
111
+ return self.num = nil unless new_val && (new_val != '')
108
112
 
109
113
  if new_val.is_a?(self.class)
110
114
  self.num = new_val.value
@@ -154,13 +158,21 @@ module StoreAsInt
154
158
  @decimals ||= self.class.decimals
155
159
  end
156
160
 
161
+ def dup
162
+ self.class.new self.num
163
+ end
164
+
157
165
  def inspect
158
166
  to_s(true)
159
167
  end
160
168
 
169
+ def matcher
170
+ @matcher ||= self.class.matcher
171
+ end
172
+
161
173
  def method_missing(name, *args, &blk)
162
- if self.class.operators[name.to_sym]
163
- self.class.new(value.__send__(name, self.class.new(*args).value))
174
+ if self.operators[name.to_sym]
175
+ self.class.new(value.__send__(name, convert(*args).value))
164
176
  else
165
177
  ret = value.send(name, *args, &blk)
166
178
  ret.is_a?(Numeric) ? self.class.new(ret) : ret
@@ -171,6 +183,11 @@ module StoreAsInt
171
183
  value < 0 ? '-' : ''
172
184
  end
173
185
 
186
+ def operators
187
+ @operators ||= self.class.operators.dup
188
+ end
189
+
190
+
174
191
  def sym
175
192
  @sym ||= self.class.sym || ''
176
193
  end
@@ -196,6 +213,7 @@ module StoreAsInt
196
213
  float: to_f,
197
214
  str: to_s,
198
215
  str_format: str_format,
216
+ str_matcher: matcher,
199
217
  str_pretty: to_s(true),
200
218
  sym: sym,
201
219
  value: value,
@@ -203,15 +221,17 @@ module StoreAsInt
203
221
  end
204
222
 
205
223
  def to_i
206
- self.num.to_i
224
+ value
207
225
  end
208
226
 
209
227
  def to_json(*args)
228
+ h = self.to_h
229
+ h.delete(:str_format)
210
230
  begin
211
- self.to_h.to_json
231
+ h.to_json
212
232
  rescue NoMethodError
213
233
  require 'json'
214
- JSON.unparse(to_h)
234
+ JSON.unparse(h)
215
235
  end
216
236
  end
217
237
 
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.12
4
+ version: 0.0.13
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-12 00:00:00.000000000 Z
11
+ date: 2018-06-15 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