oslg 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 06f0805c49f693fad81b68a22ea45477b786e96e0b2894fc32359eb7821eab81
4
- data.tar.gz: e07cf0a2d48399d7768e4fa0ba87897950f130a593721e5699f7e704735bc06d
3
+ metadata.gz: 398d4fc89206f836beea1d95578ef91629243c4f037ab9ac304359c16843e6ab
4
+ data.tar.gz: dcfb0a23e252ac13a396fda86117d7ae04aa087e9e4ec740c5efb93f2637b701
5
5
  SHA512:
6
- metadata.gz: f103e01be3e08c21952659297316eaac6faccc8e925805d3f32e3a2f6be4c53d40cf804b6f09c0b6866d8e67756b9f162ca99d398299b00bcd62d2b5a5df5c2b
7
- data.tar.gz: 74e202302c1bd8eaf0d2ac78519b3bb189d8b274b9c2cce55fa668ca2f43a40ec3741c08e97a08ad025698bf1a250c3173f238946de75efa6aee8fcb680dcaaa
6
+ metadata.gz: 5d8b0d2c29ab175e2179d6caaf10b155720a64f2063a1249e8523808020f0f46d0de743c566634e9bcf6e2f6bd0d001eb7470cfc322e67165a0b6841251032f8
7
+ data.tar.gz: 95a1e72eb075129b5e7e01f94b5a6c2341c47314733c38ae0d51b7b8b501d2b453259c03c5698a8c77aa3566d6f9a648350b4d09ed4f9ffbf3e74d07069574fd
data/README.md CHANGED
@@ -39,7 +39,7 @@ FATAL
39
39
 
40
40
  DEBUG messages aren't benign at all, but are certainly less informative for the typical Measure user.
41
41
 
42
- Initially, __oslg__ sets 2x internal variable states: `level` (INFO) and `status` (< DEBUG). The variable `level` is a user-set threshold below which less severe logs (e.g. DEBUG) are ignored. For instance, if `level` were _reset_ to DEBUG (e.g. `M.reset(M::DEBUG)`), then all DEBUG messages would also be logged. The variable `status` is reset with each new log entry if the latter's log level is more severe than its predecessor (e.g. `status == M::FATAL` if there is a single log entry registered as FATAL). To check the curent __oslg__ `status` (true or false):
42
+ Initially, __oslg__ sets 2x internal attributes: `level` (INFO) and `status` (< DEBUG). The `level` attribute is a user-set threshold below which less severe logs (e.g. DEBUG) are ignored. For instance, if `level` were _reset_ to DEBUG (e.g. `M.reset(M::DEBUG)`), then all DEBUG messages would also be logged. The `status` attribute is reset with each new log entry if the latter's log level is more severe than its predecessor (e.g. `status == M::FATAL` if there is a single log entry registered as FATAL). To check the curent __oslg__ `status` (true or false):
43
43
 
44
44
  ```
45
45
  M.debug?
@@ -48,7 +48,7 @@ M.error?
48
48
  M.fatal?
49
49
  ```
50
50
 
51
- It's sometimes not a bad idea to rely on a _clean_ slate (e.g. within RSpecs). The following flushes out all previous logs and resets `level` (INFO) and `status` (< DEBUG) - use with caution in production code!
51
+ It's sometimes not a bad idea to rely on a _clean_ slate (e.g. within RSpecs). The following purges all previous logs and resets `level` (INFO) and `status` (< DEBUG) - use with caution in production code!
52
52
 
53
53
  ```
54
54
  M.clean!
@@ -60,7 +60,7 @@ EnergyPlus will run, with e.g. out-of-range material or fluid properties, while
60
60
  M.log(M::FATAL, "Missing input JSON file")
61
61
  ```
62
62
 
63
- Consider logging non-fatal __ERROR__ messages when encountering invalid OpenStudio file entries, i.e. well-defined, yet invalid vis-à-vis EnergyPlus limitations. The invalid object could be simply ignored, while the measure pursues its (otherwise valid) calculations ... with OpenStudio ultimately launching an EnergyPlus simulation. If a simulation indeed ran (ultimately a go/no-go decision made by the EnergyPlus simulation engine), it would be up to users to decide if simulation results were valid or useful, given the context - maybe based on __oslg__ logged messages. In short, non-fatal ERROR logs should ideally point to bad input users can fix.
63
+ Consider logging non-fatal __ERROR__ messages when encountering invalid OpenStudio file entries, i.e. well-defined, yet invalid vis-à-vis EnergyPlus limitations. The invalid object could be simply ignored, while the measure pursues its (otherwise valid) calculations ... with OpenStudio ultimately launching an EnergyPlus simulation. If a simulation indeed ran (ultimately a go/no-go decision made by the EnergyPlus simulation engine), it would be up to users to decide if simulation results were valid or useful, given the context - maybe based on __oslg__ logged messages. In short, non-fatal ERROR logs should ideally point to bad input (that users can fix).
64
64
 
65
65
  ```
66
66
  M.log(M::ERROR, "Measure won't process MASSLESS materials")
@@ -96,7 +96,7 @@ These logs can be first _mapped_ to other structures (then edited), depending on
96
96
 
97
97
  ### Preset log templates
98
98
 
99
- Typically, developers would first catch bad input, log an error message and possibly exit by returning a variable (e.g. __false__, __nil__), e.g.:
99
+ Typically, developers would first catch bad input, log an error message and possibly exit by returning an object (e.g. __false__, __nil__), e.g.:
100
100
 
101
101
  ```
102
102
  unless var.is_a?(Array)
@@ -105,7 +105,7 @@ unless var.is_a?(Array)
105
105
  end
106
106
  ```
107
107
 
108
- The following are __oslg__ one-liner methods that _log & return_ in one go. These are for some of the most common checks OpenStudio SDK Ruby developers are likely to need. The methods require _valid_ arguments for __oslg__ to actually log. Although often expecting strings as arguments, the methods will try to convert other types to strings (e.g. classes, numbers, even entire arrays) if possible.
108
+ The following are __oslg__ one-liner methods that _log & return_ in one go. These are for some of the most common checks OpenStudio SDK Ruby developers are likely to need. The methods require _valid_ arguments for __oslg__ to actually log. Although often expecting either strings or integers as arguments, the methods will try to convert other types to strings (e.g. classes, numbers, even entire arrays) or integers if possible.
109
109
 
110
110
  ---
111
111
 
@@ -125,8 +125,8 @@ The 3rd argument (e.g. _0_) is ignored unless `> 0` - a useful option when asser
125
125
 
126
126
  ```
127
127
  def sum(areas, units)
128
- return M.invalid("areas", "sum", 1) unless areas
129
- return M.invalid("units", "sum", 2) unless units
128
+ return M.invalid("areas", "sum", 1) unless areas.respond_to?(:to_f)
129
+ return M.invalid("units", "sum", 2) unless units.respond_to?(:to_s)
130
130
  ...
131
131
  end
132
132
  ```
data/lib/oslg/oslog.rb CHANGED
@@ -171,28 +171,32 @@ module OSlg
171
171
  #
172
172
  # @param id [String] invalid object identifier
173
173
  # @param mth [String] calling method identifier
174
- # @param ord [String] calling method argument order number of obj (optional)
174
+ # @param ord [Integer] calling method argument order number of obj (optional)
175
175
  # @param lvl [Integer] DEBUG, INFO, WARN, ERROR or FATAL (optional)
176
176
  # @param res [Object] what to return (optional)
177
177
  #
178
178
  # @return [Object] return object if specified by user
179
- # @return [Nil] nil if return object missing or invalid
179
+ # @return [Nil] nil if return object undefined
180
180
  def invalid(id = "", mth = "", ord = 0, lvl = DEBUG, res = nil)
181
- return nil unless defined?(res)
182
- return res unless defined?(id ) && id
183
- return res unless defined?(mth) && mth
184
- return res unless defined?(ord) && ord
185
- return res unless defined?(lvl) && lvl
181
+ return res unless id.respond_to?(:to_s)
182
+ return res unless mth.respond_to?(:to_s)
183
+ return res unless ord.respond_to?(:to_i)
184
+ return res unless lvl.respond_to?(:to_i)
185
+
186
+ id = id.to_s.strip
186
187
  mth = mth.to_s.strip
187
- mth = mth[0...60] + " ..." if mth.length > 60
188
- return res if mth.empty?
189
- id = id.to_s.strip
188
+ ord = ord.to_i
189
+ lvl = lvl.to_i
190
+
190
191
  id = id[0...60] + " ..." if id.length > 60
191
192
  return res if id.empty?
193
+
194
+ mth = mth[0...60] + " ..." if mth.length > 60
195
+ return res if mth.empty?
196
+
192
197
  msg = "Invalid '#{id}' "
193
- msg += "arg ##{ord} " if ord.is_a?(Integer) && ord > 0
198
+ msg += "arg ##{ord} " if ord > 0
194
199
  msg += "(#{mth})"
195
- lvl = lvl.to_i unless lvl.is_a?(Integer)
196
200
  log(lvl, msg) if lvl >= DEBUG && lvl <= FATAL
197
201
  res
198
202
  end
@@ -208,24 +212,25 @@ module OSlg
208
212
  # @param res [Object] what to return (optional)
209
213
  #
210
214
  # @return [Object] return object if specified by user
211
- # @return [Nil] nil if return object missing or invalid
215
+ # @return [Nil] nil if return object undefined
212
216
  def mismatch(id = "", obj = nil, cl = nil, mth = "", lvl = DEBUG, res = nil)
213
- return nil unless defined?(res)
214
- return res unless defined?(id ) && id
215
- return res unless defined?(obj) && obj
216
- return res unless defined?(cl ) && cl
217
- return res unless defined?(mth) && mth
218
- return res unless defined?(lvl) && lvl
217
+ return res unless id.respond_to?(:to_s)
218
+ return res unless cl.is_a?(Class)
219
+ return res if obj.is_a?(cl)
220
+ return res unless mth.respond_to?(:to_s)
221
+ return res unless lvl.respond_to?(:to_i)
222
+
219
223
  mth = mth.to_s.strip
220
- mth = mth[0...60] + " ..." if mth.length > 60
221
- return res if mth.empty?
222
- id = id.to_s.strip
224
+ id = id.to_s.strip
225
+ lvl = lvl.to_i
226
+
223
227
  id = id[0...60] + " ..." if id.length > 60
224
228
  return res if id.empty?
225
- return res unless cl.is_a?(Class)
226
- return res if obj.is_a?(cl)
229
+
230
+ mth = mth[0...60] + " ..." if mth.length > 60
231
+ return res if mth.empty?
232
+
227
233
  msg = "'#{id}' #{obj.class}? expecting #{cl} (#{mth})"
228
- lvl = lvl.to_i unless lvl.is_a?(Integer)
229
234
  log(lvl, msg) if lvl >= DEBUG && lvl <= FATAL
230
235
  res
231
236
  end
@@ -241,24 +246,25 @@ module OSlg
241
246
  # @param res [Object] what to return (optional)
242
247
  #
243
248
  # @return [Object] return object if specified by user
244
- # @return [Nil] nil if return object missing or invalid
249
+ # @return [Nil] nil if return object undefined
245
250
  def hashkey(id = "", hsh = {}, key = "", mth = "", lvl = DEBUG, res = nil)
246
- return nil unless defined?(res)
247
- return res unless defined?(id ) && id
248
- return res unless defined?(hsh) && hsh
249
- return res unless defined?(key) && key
250
- return res unless defined?(mth) && mth
251
- return res unless defined?(lvl) && lvl
251
+ return res unless id.respond_to?(:to_s)
252
+ return res unless hsh.is_a?(Hash)
253
+ return res if hsh.key?(key)
254
+ return res unless mth.respond_to?(:to_s)
255
+ return res unless lvl.respond_to?(:to_i)
256
+
257
+ id = id.to_s.strip
252
258
  mth = mth.to_s.strip
253
- mth = mth[0...60] + " ..." if mth.length > 60
254
- return res if mth.empty?
255
- id = id.to_s.strip
259
+ lvl = lvl.to_i
260
+
256
261
  id = id[0...60] + " ..." if id.length > 60
257
262
  return res if id.empty?
258
- return mismatch(id, hsh, Hash, mth, lvl, res) unless hsh.is_a?(Hash)
259
- return res if hsh.key?(key)
263
+
264
+ mth = mth[0...60] + " ..." if mth.length > 60
265
+ return res if mth.empty?
266
+
260
267
  msg = "Missing '#{key}' key in '#{id}' Hash (#{mth})"
261
- lvl = lvl.to_i unless lvl.is_a?(Integer)
262
268
  log(lvl, msg) if lvl >= DEBUG && lvl <= FATAL
263
269
  res
264
270
  end
@@ -272,20 +278,23 @@ module OSlg
272
278
  # @param res [Object] what to return (optional)
273
279
  #
274
280
  # @return [Object] return object if specified by user
275
- # @return [Nil] nil if return object missing or invalid
281
+ # @return [Nil] nil if return object undefined
276
282
  def empty(id = "", mth = "", lvl = DEBUG, res = nil)
277
- return nil unless defined?(res)
278
- return res unless defined?(id ) && id
279
- return res unless defined?(mth) && mth
280
- return res unless defined?(lvl) && lvl
283
+ return res unless id.respond_to?(:to_s)
284
+ return res unless mth.respond_to?(:to_s)
285
+ return res unless lvl.respond_to?(:to_i)
286
+
287
+ id = id.to_s.strip
281
288
  mth = mth.to_s.strip
282
- mth = mth[0...60] + " ..." if mth.length > 60
283
- return res if mth.empty?
284
- id = id.to_s.strip
289
+ lvl = lvl.to_i
290
+
285
291
  id = id[0...60] + " ..." if id.length > 60
286
292
  return res if id.empty?
293
+
294
+ mth = mth[0...60] + " ..." if mth.length > 60
295
+ return res if mth.empty?
296
+
287
297
  msg = "Empty '#{id}' (#{mth})"
288
- lvl = lvl.to_i unless lvl.is_a?(Integer)
289
298
  log(lvl, msg) if lvl >= DEBUG && lvl <= FATAL
290
299
  res
291
300
  end
@@ -299,20 +308,24 @@ module OSlg
299
308
  # @param res [Object] what to return (optional)
300
309
  #
301
310
  # @return [Object] return object if specified by user
302
- # @return [Nil] nil if return object missing or invalid
311
+ # @return [Nil] nil if return object undefined
303
312
  def zero(id = "", mth = "", lvl = DEBUG, res = nil)
304
- return nil unless defined?(res)
305
- return res unless defined?(id ) && id
306
- return res unless defined?(mth) && mth
307
- return res unless defined?(lvl) && lvl
313
+ return res unless id.respond_to?(:to_s)
314
+ return res unless mth.respond_to?(:to_s)
315
+ return res unless lvl.respond_to?(:to_i)
316
+
317
+ id = id.to_s.strip
308
318
  mth = mth.to_s.strip
309
- mth = mth[0...60] + " ..." if mth.length > 60
310
- return res if mth.empty?
311
- id = id.to_s.strip
319
+ ord = ord.to_i
320
+ lvl = lvl.to_i
321
+
312
322
  id = id[0...60] + " ..." if id.length > 60
313
323
  return res if id.empty?
324
+
325
+ mth = mth[0...60] + " ..." if mth.length > 60
326
+ return res if mth.empty?
327
+
314
328
  msg = "Zero '#{id}' (#{mth})"
315
- lvl = lvl.to_i unless lvl.is_a?(Integer)
316
329
  log(lvl, msg) if lvl >= DEBUG && lvl <= FATAL
317
330
  res
318
331
  end
@@ -326,20 +339,24 @@ module OSlg
326
339
  # @param res [Object] what to return (optional)
327
340
  #
328
341
  # @return [Object] return object if specified by user
329
- # @return [Nil] nil if return object missing or invalid
342
+ # @return [Nil] nil if return object undefined
330
343
  def negative(id = "", mth = "", lvl = DEBUG, res = nil)
331
- return nil unless defined?(res)
332
- return res unless defined?(id ) && id
333
- return res unless defined?(mth) && mth
334
- return res unless defined?(lvl) && lvl
344
+ return res unless id.respond_to?(:to_s)
345
+ return res unless mth.respond_to?(:to_s)
346
+ return res unless lvl.respond_to?(:to_i)
347
+
348
+ id = id.to_s.strip
335
349
  mth = mth.to_s.strip
336
- mth = mth[0...60] + " ..." if mth.length > 60
337
- return res if mth.empty?
338
- id = id.to_s.strip
350
+ ord = ord.to_i
351
+ lvl = lvl.to_i
352
+
339
353
  id = id[0...60] + " ..." if id.length > 60
340
354
  return res if id.empty?
355
+
356
+ mth = mth[0...60] + " ..." if mth.length > 60
357
+ return res if mth.empty?
358
+
341
359
  msg = "Negative '#{id}' (#{mth})"
342
- lvl = lvl.to_i unless lvl.is_a?(Integer)
343
360
  log(lvl, msg) if lvl >= DEBUG && lvl <= FATAL
344
361
  res
345
362
  end
data/lib/oslg/version.rb CHANGED
@@ -29,5 +29,5 @@
29
29
  # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
30
 
31
31
  module OSlg
32
- VERSION = "0.2.4".freeze
32
+ VERSION = "0.2.5".freeze
33
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oslg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Bourgeois
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-31 00:00:00.000000000 Z
11
+ date: 2022-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -76,7 +76,7 @@ licenses:
76
76
  - BSD-3-Clause
77
77
  metadata:
78
78
  homepage_uri: https://github.com/rd2/oslg
79
- source_code_uri: https://github.com/rd2/oslg/tree/v0.2.4
79
+ source_code_uri: https://github.com/rd2/oslg/tree/v0.2.5
80
80
  bug_tracker_uri: https://github.com/rd2/oslg/issues
81
81
  post_install_message:
82
82
  rdoc_options: []