oslg 0.2.4 → 0.2.6

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: 5d9b0ecd08d5975a017a4133b83cd7deea1a21427d923651ff629347ee4b8e83
4
+ data.tar.gz: 637c081134c0fc036048c62a17bf7e95087c807c34921bd80ebb3d53f0996346
5
5
  SHA512:
6
- metadata.gz: f103e01be3e08c21952659297316eaac6faccc8e925805d3f32e3a2f6be4c53d40cf804b6f09c0b6866d8e67756b9f162ca99d398299b00bcd62d2b5a5df5c2b
7
- data.tar.gz: 74e202302c1bd8eaf0d2ac78519b3bb189d8b274b9c2cce55fa668ca2f43a40ec3741c08e97a08ad025698bf1a250c3173f238946de75efa6aee8fcb680dcaaa
6
+ metadata.gz: cf5fddfd6703ac80fdcc94818db3f9c5d58c27a9f7617db8d04b92b78b9e442937551857fa4c7c9a1d470703f89499a484d55f49c1b8e30ebb72cd8266d63676
7
+ data.tar.gz: 36411cd8958dd7e387e34ecd901c9cc12ff62cf37fb483e3c5d88954732857eaf796609cc358dea417ece8fe06f11f1e5526e2e1760a5444c3ffcdbdcd3d14a2
@@ -7,7 +7,7 @@ on:
7
7
 
8
8
  jobs:
9
9
  test_300x:
10
- runs-on: ubuntu-18.04
10
+ runs-on: ubuntu-22.04
11
11
  steps:
12
12
  - name: Check out repository
13
13
  uses: actions/checkout@v2
@@ -23,7 +23,7 @@ jobs:
23
23
  docker exec -t test bundle exec rake
24
24
  docker kill test
25
25
  test_321x:
26
- runs-on: ubuntu-18.04
26
+ runs-on: ubuntu-22.04
27
27
  steps:
28
28
  - name: Check out repository
29
29
  uses: actions/checkout@v2
@@ -39,7 +39,7 @@ jobs:
39
39
  docker exec -t test bundle exec rake
40
40
  docker kill test
41
41
  test_330x:
42
- runs-on: ubuntu-20.04
42
+ runs-on: ubuntu-22.04
43
43
  steps:
44
44
  - name: Check out repository
45
45
  uses: actions/checkout@v2
@@ -55,7 +55,7 @@ jobs:
55
55
  docker exec -t test bundle exec rake
56
56
  docker kill test
57
57
  test_340x:
58
- runs-on: ubuntu-20.04
58
+ runs-on: ubuntu-22.04
59
59
  steps:
60
60
  - name: Check out repository
61
61
  uses: actions/checkout@v2
@@ -70,3 +70,19 @@ jobs:
70
70
  docker exec -t test bundle update
71
71
  docker exec -t test bundle exec rake
72
72
  docker kill test
73
+ test_351x:
74
+ runs-on: ubuntu-22.04
75
+ steps:
76
+ - name: Check out repository
77
+ uses: actions/checkout@v2
78
+ - name: Run Tests
79
+ run: |
80
+ echo $(pwd)
81
+ echo $(ls)
82
+ docker pull nrel/openstudio:3.5.1
83
+ docker run --name test --rm -d -t -v $(pwd):/work -w /work nrel/openstudio:3.5.1
84
+ docker exec -t test pwd
85
+ docker exec -t test ls
86
+ docker exec -t test bundle update
87
+ docker exec -t test bundle exec rake
88
+ docker kill test
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  BSD 3-Clause License
2
2
 
3
- Copyright (c) 2022, Denis Bourgeois
3
+ Copyright (c) 2022-2023, Denis Bourgeois
4
4
  All rights reserved.
5
5
 
6
6
  Redistribution and use in source and binary forms, with or without
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
@@ -1,6 +1,6 @@
1
1
  # BSD 3-Clause License
2
2
  #
3
- # Copyright (c) 2022, Denis Bourgeois
3
+ # Copyright (c) 2022-2023, Denis Bourgeois
4
4
  # All rights reserved.
5
5
  #
6
6
  # Redistribution and use in source and binary forms, with or without
@@ -127,6 +127,7 @@ module OSlg
127
127
  # @return [String] "DEBUG", "INFO", "WARN", "ERROR" or "FATAL"
128
128
  def tag(level)
129
129
  return @@tag[level] if level >= DEBUG && level <= FATAL
130
+
130
131
  ""
131
132
  end
132
133
 
@@ -138,6 +139,7 @@ module OSlg
138
139
  # @return [String] preset OSlg message
139
140
  def msg(status)
140
141
  return @@msg[status] if status >= DEBUG && status <= FATAL
142
+
141
143
  ""
142
144
  end
143
145
 
@@ -163,6 +165,7 @@ module OSlg
163
165
  @@logs << {level: level, message: message}
164
166
  @@status = level if level > @@status
165
167
  end
168
+
166
169
  @@status
167
170
  end
168
171
 
@@ -171,29 +174,34 @@ module OSlg
171
174
  #
172
175
  # @param id [String] invalid object identifier
173
176
  # @param mth [String] calling method identifier
174
- # @param ord [String] calling method argument order number of obj (optional)
177
+ # @param ord [Integer] calling method argument order number of obj (optional)
175
178
  # @param lvl [Integer] DEBUG, INFO, WARN, ERROR or FATAL (optional)
176
179
  # @param res [Object] what to return (optional)
177
180
  #
178
181
  # @return [Object] return object if specified by user
179
- # @return [Nil] nil if return object missing or invalid
182
+ # @return [Nil] nil if return object undefined
180
183
  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
184
+ return res unless id.respond_to?(:to_s)
185
+ return res unless mth.respond_to?(:to_s)
186
+ return res unless ord.respond_to?(:to_i)
187
+ return res unless lvl.respond_to?(:to_i)
188
+
189
+ id = id.to_s.strip
186
190
  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
191
+ ord = ord.to_i
192
+ lvl = lvl.to_i
193
+
190
194
  id = id[0...60] + " ..." if id.length > 60
191
195
  return res if id.empty?
192
- msg = "Invalid '#{id}' "
193
- msg += "arg ##{ord} " if ord.is_a?(Integer) && ord > 0
196
+
197
+ mth = mth[0...60] + " ..." if mth.length > 60
198
+ return res if mth.empty?
199
+
200
+ msg = "Invalid '#{id}' "
201
+ msg += "arg ##{ord} " if ord > 0
194
202
  msg += "(#{mth})"
195
- lvl = lvl.to_i unless lvl.is_a?(Integer)
196
203
  log(lvl, msg) if lvl >= DEBUG && lvl <= FATAL
204
+
197
205
  res
198
206
  end
199
207
 
@@ -208,25 +216,27 @@ module OSlg
208
216
  # @param res [Object] what to return (optional)
209
217
  #
210
218
  # @return [Object] return object if specified by user
211
- # @return [Nil] nil if return object missing or invalid
219
+ # @return [Nil] nil if return object undefined
212
220
  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
221
+ return res unless id.respond_to?(:to_s)
222
+ return res unless cl.is_a?(Class)
223
+ return res if obj.is_a?(cl)
224
+ return res unless mth.respond_to?(:to_s)
225
+ return res unless lvl.respond_to?(:to_i)
226
+
219
227
  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
228
+ id = id.to_s.strip
229
+ lvl = lvl.to_i
230
+
223
231
  id = id[0...60] + " ..." if id.length > 60
224
232
  return res if id.empty?
225
- return res unless cl.is_a?(Class)
226
- return res if obj.is_a?(cl)
233
+
234
+ mth = mth[0...60] + " ..." if mth.length > 60
235
+ return res if mth.empty?
236
+
227
237
  msg = "'#{id}' #{obj.class}? expecting #{cl} (#{mth})"
228
- lvl = lvl.to_i unless lvl.is_a?(Integer)
229
238
  log(lvl, msg) if lvl >= DEBUG && lvl <= FATAL
239
+
230
240
  res
231
241
  end
232
242
 
@@ -241,25 +251,27 @@ module OSlg
241
251
  # @param res [Object] what to return (optional)
242
252
  #
243
253
  # @return [Object] return object if specified by user
244
- # @return [Nil] nil if return object missing or invalid
254
+ # @return [Nil] nil if return object undefined
245
255
  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
256
+ return res unless id.respond_to?(:to_s)
257
+ return res unless hsh.is_a?(Hash)
258
+ return res if hsh.key?(key)
259
+ return res unless mth.respond_to?(:to_s)
260
+ return res unless lvl.respond_to?(:to_i)
261
+
262
+ id = id.to_s.strip
252
263
  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
264
+ lvl = lvl.to_i
265
+
256
266
  id = id[0...60] + " ..." if id.length > 60
257
267
  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)
260
- msg = "Missing '#{key}' key in '#{id}' Hash (#{mth})"
261
- lvl = lvl.to_i unless lvl.is_a?(Integer)
268
+
269
+ mth = mth[0...60] + " ..." if mth.length > 60
270
+ return res if mth.empty?
271
+
272
+ msg = "Missing '#{key}' key in '#{id}' Hash (#{mth})"
262
273
  log(lvl, msg) if lvl >= DEBUG && lvl <= FATAL
274
+
263
275
  res
264
276
  end
265
277
 
@@ -272,21 +284,25 @@ module OSlg
272
284
  # @param res [Object] what to return (optional)
273
285
  #
274
286
  # @return [Object] return object if specified by user
275
- # @return [Nil] nil if return object missing or invalid
287
+ # @return [Nil] nil if return object undefined
276
288
  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
289
+ return res unless id.respond_to?(:to_s)
290
+ return res unless mth.respond_to?(:to_s)
291
+ return res unless lvl.respond_to?(:to_i)
292
+
293
+ id = id.to_s.strip
281
294
  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
295
+ lvl = lvl.to_i
296
+
285
297
  id = id[0...60] + " ..." if id.length > 60
286
298
  return res if id.empty?
287
- msg = "Empty '#{id}' (#{mth})"
288
- lvl = lvl.to_i unless lvl.is_a?(Integer)
299
+
300
+ mth = mth[0...60] + " ..." if mth.length > 60
301
+ return res if mth.empty?
302
+
303
+ msg = "Empty '#{id}' (#{mth})"
289
304
  log(lvl, msg) if lvl >= DEBUG && lvl <= FATAL
305
+
290
306
  res
291
307
  end
292
308
 
@@ -299,21 +315,26 @@ module OSlg
299
315
  # @param res [Object] what to return (optional)
300
316
  #
301
317
  # @return [Object] return object if specified by user
302
- # @return [Nil] nil if return object missing or invalid
318
+ # @return [Nil] nil if return object undefined
303
319
  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
320
+ return res unless id.respond_to?(:to_s)
321
+ return res unless mth.respond_to?(:to_s)
322
+ return res unless lvl.respond_to?(:to_i)
323
+
324
+ id = id.to_s.strip
308
325
  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
326
+ ord = ord.to_i
327
+ lvl = lvl.to_i
328
+
312
329
  id = id[0...60] + " ..." if id.length > 60
313
330
  return res if id.empty?
314
- msg = "Zero '#{id}' (#{mth})"
315
- lvl = lvl.to_i unless lvl.is_a?(Integer)
331
+
332
+ mth = mth[0...60] + " ..." if mth.length > 60
333
+ return res if mth.empty?
334
+
335
+ msg = "Zero '#{id}' (#{mth})"
316
336
  log(lvl, msg) if lvl >= DEBUG && lvl <= FATAL
337
+
317
338
  res
318
339
  end
319
340
 
@@ -326,21 +347,26 @@ module OSlg
326
347
  # @param res [Object] what to return (optional)
327
348
  #
328
349
  # @return [Object] return object if specified by user
329
- # @return [Nil] nil if return object missing or invalid
350
+ # @return [Nil] nil if return object undefined
330
351
  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
352
+ return res unless id.respond_to?(:to_s)
353
+ return res unless mth.respond_to?(:to_s)
354
+ return res unless lvl.respond_to?(:to_i)
355
+
356
+ id = id.to_s.strip
335
357
  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
358
+ ord = ord.to_i
359
+ lvl = lvl.to_i
360
+
339
361
  id = id[0...60] + " ..." if id.length > 60
340
362
  return res if id.empty?
341
- msg = "Negative '#{id}' (#{mth})"
342
- lvl = lvl.to_i unless lvl.is_a?(Integer)
363
+
364
+ mth = mth[0...60] + " ..." if mth.length > 60
365
+ return res if mth.empty?
366
+
367
+ msg = "Negative '#{id}' (#{mth})"
343
368
  log(lvl, msg) if lvl >= DEBUG && lvl <= FATAL
369
+
344
370
  res
345
371
  end
346
372
 
@@ -351,6 +377,7 @@ module OSlg
351
377
  def clean!
352
378
  @@status = 0
353
379
  @@logs = []
380
+
354
381
  @@level
355
382
  end
356
383
 
data/lib/oslg/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # BSD 3-Clause License
2
2
  #
3
- # Copyright (c) 2022, Denis Bourgeois
3
+ # Copyright (c) 2022-2023, Denis Bourgeois
4
4
  # All rights reserved.
5
5
  #
6
6
  # Redistribution and use in source and binary forms, with or without
@@ -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.6".freeze
33
33
  end
data/lib/oslg.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # BSD 3-Clause License
2
2
  #
3
- # Copyright (c) 2022, Denis Bourgeois
3
+ # Copyright (c) 2022-2023, Denis Bourgeois
4
4
  # All rights reserved.
5
5
  #
6
6
  # Redistribution and use in source and binary forms, with or without
data/oslg.gemspec CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
31
31
  s.add_development_dependency "rake", "~> 13.0"
32
32
  s.add_development_dependency "rspec", "~> 3.11"
33
33
 
34
- s.metadata["homepage_uri"] = s.homepage
34
+ s.metadata["homepage_uri" ] = s.homepage
35
35
  s.metadata["source_code_uri"] = "#{s.homepage}/tree/v#{s.version}"
36
36
  s.metadata["bug_tracker_uri"] = "#{s.homepage}/issues"
37
37
  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.6
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: 2023-01-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.6
80
80
  bug_tracker_uri: https://github.com/rd2/oslg/issues
81
81
  post_install_message:
82
82
  rdoc_options: []