cdss-ruby 0.1.0

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 (99) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +86 -0
  3. data/CHANGELOG.md +5 -0
  4. data/CODE_OF_CONDUCT.md +84 -0
  5. data/README.md +101 -0
  6. data/Rakefile +26 -0
  7. data/docs/Cdss/AdminCalls.html +399 -0
  8. data/docs/Cdss/Analysis.html +972 -0
  9. data/docs/Cdss/Client.html +581 -0
  10. data/docs/Cdss/Climate.html +1257 -0
  11. data/docs/Cdss/Concerns/LogReadingAttributes.html +406 -0
  12. data/docs/Cdss/Concerns/WellReadingAttributes.html +414 -0
  13. data/docs/Cdss/Concerns.html +117 -0
  14. data/docs/Cdss/GroundWater.html +945 -0
  15. data/docs/Cdss/Models/AdminCall.html +252 -0
  16. data/docs/Cdss/Models/Analysis.html +397 -0
  17. data/docs/Cdss/Models/CallAnalysis.html +140 -0
  18. data/docs/Cdss/Models/ClimateStation.html +249 -0
  19. data/docs/Cdss/Models/DiversionRecord.html +248 -0
  20. data/docs/Cdss/Models/Reading.html +301 -0
  21. data/docs/Cdss/Models/ReferenceTable.html +339 -0
  22. data/docs/Cdss/Models/RouteAnalysis.html +140 -0
  23. data/docs/Cdss/Models/SourceRoute.html +140 -0
  24. data/docs/Cdss/Models/Station.html +248 -0
  25. data/docs/Cdss/Models/Structure.html +259 -0
  26. data/docs/Cdss/Models/WaterClass.html +249 -0
  27. data/docs/Cdss/Models/WaterRight.html +255 -0
  28. data/docs/Cdss/Models/Well.html +251 -0
  29. data/docs/Cdss/Models.html +117 -0
  30. data/docs/Cdss/Parser.html +2155 -0
  31. data/docs/Cdss/Parsers/AdminCallsParser.html +201 -0
  32. data/docs/Cdss/Parsers/AnalysisParser.html +296 -0
  33. data/docs/Cdss/Parsers/BaseParser.html +207 -0
  34. data/docs/Cdss/Parsers/ClimateParser.html +253 -0
  35. data/docs/Cdss/Parsers/ReadingParser.html +201 -0
  36. data/docs/Cdss/Parsers/ReferenceTablesParser.html +201 -0
  37. data/docs/Cdss/Parsers/StationParser.html +201 -0
  38. data/docs/Cdss/Parsers/StructuresParser.html +305 -0
  39. data/docs/Cdss/Parsers/WaterRightsParser.html +219 -0
  40. data/docs/Cdss/Parsers/WellParser.html +357 -0
  41. data/docs/Cdss/Parsers.html +117 -0
  42. data/docs/Cdss/ReferenceTables.html +332 -0
  43. data/docs/Cdss/Structures.html +1132 -0
  44. data/docs/Cdss/SurfaceWater.html +798 -0
  45. data/docs/Cdss/Telemetry.html +763 -0
  46. data/docs/Cdss/Utils.html +1276 -0
  47. data/docs/Cdss/WaterRights.html +634 -0
  48. data/docs/Cdss.html +292 -0
  49. data/docs/_index.html +493 -0
  50. data/docs/class_list.html +54 -0
  51. data/docs/css/common.css +1 -0
  52. data/docs/css/full_list.css +58 -0
  53. data/docs/css/style.css +503 -0
  54. data/docs/file.README.html +108 -0
  55. data/docs/file_list.html +59 -0
  56. data/docs/frames.html +22 -0
  57. data/docs/index.html +108 -0
  58. data/docs/js/app.js +344 -0
  59. data/docs/js/full_list.js +242 -0
  60. data/docs/js/jquery.js +4 -0
  61. data/docs/method_list.html +790 -0
  62. data/docs/top-level-namespace.html +110 -0
  63. data/lib/cdss/admin_calls.rb +44 -0
  64. data/lib/cdss/analysis.rb +183 -0
  65. data/lib/cdss/client.rb +121 -0
  66. data/lib/cdss/climate.rb +155 -0
  67. data/lib/cdss/concerns/log_reading_attributes.rb +48 -0
  68. data/lib/cdss/concerns/well_reading_attributes.rb +56 -0
  69. data/lib/cdss/ground_water.rb +112 -0
  70. data/lib/cdss/models/admin_call.rb +45 -0
  71. data/lib/cdss/models/analysis.rb +77 -0
  72. data/lib/cdss/models/climate_station.rb +40 -0
  73. data/lib/cdss/models/reading.rb +54 -0
  74. data/lib/cdss/models/reference_table.rb +56 -0
  75. data/lib/cdss/models/station.rb +40 -0
  76. data/lib/cdss/models/structure.rb +101 -0
  77. data/lib/cdss/models/water_right.rb +47 -0
  78. data/lib/cdss/models/well.rb +43 -0
  79. data/lib/cdss/parser.rb +172 -0
  80. data/lib/cdss/parsers/admin_calls_parser.rb +47 -0
  81. data/lib/cdss/parsers/analysis_parser.rb +124 -0
  82. data/lib/cdss/parsers/base_parser.rb +18 -0
  83. data/lib/cdss/parsers/climate_parser.rb +86 -0
  84. data/lib/cdss/parsers/reading_parser.rb +90 -0
  85. data/lib/cdss/parsers/reference_tables_parser.rb +55 -0
  86. data/lib/cdss/parsers/station_parser.rb +42 -0
  87. data/lib/cdss/parsers/structures_parser.rb +96 -0
  88. data/lib/cdss/parsers/water_rights_parser.rb +77 -0
  89. data/lib/cdss/parsers/well_parser.rb +107 -0
  90. data/lib/cdss/reference_tables.rb +147 -0
  91. data/lib/cdss/structures.rb +235 -0
  92. data/lib/cdss/surface_water.rb +186 -0
  93. data/lib/cdss/telemetry.rb +98 -0
  94. data/lib/cdss/utils.rb +152 -0
  95. data/lib/cdss/version.rb +5 -0
  96. data/lib/cdss/water_rights.rb +95 -0
  97. data/lib/cdss.rb +27 -0
  98. data/sig/cdss/ruby.rbs +6 -0
  99. metadata +272 -0
@@ -0,0 +1,1276 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>
7
+ Module: Cdss::Utils
8
+
9
+ &mdash; Documentation by YARD 0.9.37
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="../css/style.css" type="text/css" />
14
+
15
+ <link rel="stylesheet" href="../css/common.css" type="text/css" />
16
+
17
+ <script type="text/javascript">
18
+ pathId = "Cdss::Utils";
19
+ relpath = '../';
20
+ </script>
21
+
22
+
23
+ <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
24
+
25
+ <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
26
+
27
+
28
+ </head>
29
+ <body>
30
+ <div class="nav_wrap">
31
+ <iframe id="nav" src="../class_list.html?1"></iframe>
32
+ <div id="resizer"></div>
33
+ </div>
34
+
35
+ <div id="main" tabindex="-1">
36
+ <div id="header">
37
+ <div id="menu">
38
+
39
+ <a href="../_index.html">Index (U)</a> &raquo;
40
+ <span class='title'><span class='object_link'><a href="../Cdss.html" title="Cdss (module)">Cdss</a></span></span>
41
+ &raquo;
42
+ <span class="title">Utils</span>
43
+
44
+ </div>
45
+
46
+ <div id="search">
47
+
48
+ <a class="full_list_link" id="class_list_link"
49
+ href="../class_list.html">
50
+
51
+ <svg width="24" height="24">
52
+ <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
+ <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
+ <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
+ </svg>
56
+ </a>
57
+
58
+ </div>
59
+ <div class="clear"></div>
60
+ </div>
61
+
62
+ <div id="content"><h1>Module: Cdss::Utils
63
+
64
+
65
+
66
+ </h1>
67
+ <div class="box_info">
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+ <dl>
78
+ <dt>Included in:</dt>
79
+ <dd><span class='object_link'><a href="AdminCalls.html" title="Cdss::AdminCalls (module)">AdminCalls</a></span>, <span class='object_link'><a href="Analysis.html" title="Cdss::Analysis (module)">Analysis</a></span>, <span class='object_link'><a href="Climate.html" title="Cdss::Climate (module)">Climate</a></span>, <span class='object_link'><a href="GroundWater.html" title="Cdss::GroundWater (module)">GroundWater</a></span>, <span class='object_link'><a href="Parsers/BaseParser.html" title="Cdss::Parsers::BaseParser (module)">Parsers::BaseParser</a></span>, <span class='object_link'><a href="ReferenceTables.html" title="Cdss::ReferenceTables (module)">ReferenceTables</a></span>, <span class='object_link'><a href="Structures.html" title="Cdss::Structures (module)">Structures</a></span>, <span class='object_link'><a href="SurfaceWater.html" title="Cdss::SurfaceWater (module)">SurfaceWater</a></span>, <span class='object_link'><a href="Telemetry.html" title="Cdss::Telemetry (module)">Telemetry</a></span>, <span class='object_link'><a href="WaterRights.html" title="Cdss::WaterRights (module)">WaterRights</a></span></dd>
80
+ </dl>
81
+
82
+
83
+
84
+ <dl>
85
+ <dt>Defined in:</dt>
86
+ <dd>lib/cdss/utils.rb</dd>
87
+ </dl>
88
+
89
+ </div>
90
+
91
+ <h2>Overview</h2><div class="docstring">
92
+ <div class="discussion">
93
+
94
+ <p>Provides utility methods for handling dates, query parameters, and API pagination.</p>
95
+
96
+ <p>This module contains helper methods used across the CDSS API client for data formatting, safe type conversion, and managing paginated responses.</p>
97
+
98
+
99
+ </div>
100
+ </div>
101
+ <div class="tags">
102
+
103
+
104
+ </div>
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+ <h2>
113
+ Instance Method Summary
114
+ <small><a href="#" class="summary_toggle">collapse</a></small>
115
+ </h2>
116
+
117
+ <ul class="summary">
118
+
119
+ <li class="public ">
120
+ <span class="summary_signature">
121
+
122
+ <a href="#batch_dates-instance_method" title="#batch_dates (instance method)">#<strong>batch_dates</strong>(start_date, end_date) &#x21d2; Array&lt;Array&lt;Date&gt;&gt; </a>
123
+
124
+
125
+
126
+ </span>
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+ <span class="summary_desc"><div class='inline'>
137
+ <p>Splits a date range into yearly chunks.</p>
138
+ </div></span>
139
+
140
+ </li>
141
+
142
+
143
+ <li class="public ">
144
+ <span class="summary_signature">
145
+
146
+ <a href="#build_query-instance_method" title="#build_query (instance method)">#<strong>build_query</strong>(params = {}, encode: false) &#x21d2; Hash </a>
147
+
148
+
149
+
150
+ </span>
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+ <span class="summary_desc"><div class='inline'>
161
+ <p>Builds a query hash for API requests.</p>
162
+ </div></span>
163
+
164
+ </li>
165
+
166
+
167
+ <li class="public ">
168
+ <span class="summary_signature">
169
+
170
+ <a href="#fetch_paginated_data-instance_method" title="#fetch_paginated_data (instance method)">#<strong>fetch_paginated_data</strong>(endpoint:, query:) {|Hash| ... } &#x21d2; Array </a>
171
+
172
+
173
+
174
+ </span>
175
+
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+ <span class="summary_desc"><div class='inline'>
185
+ <p>Fetches all pages of data from a paginated API endpoint.</p>
186
+ </div></span>
187
+
188
+ </li>
189
+
190
+
191
+ <li class="public ">
192
+ <span class="summary_signature">
193
+
194
+ <a href="#format_date-instance_method" title="#format_date (instance method)">#<strong>format_date</strong>(date, special_format: false) &#x21d2; String<sup>?</sup> </a>
195
+
196
+
197
+
198
+ </span>
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+ <span class="summary_desc"><div class='inline'>
209
+ <p>Formats a date for API requests.</p>
210
+ </div></span>
211
+
212
+ </li>
213
+
214
+
215
+ <li class="public ">
216
+ <span class="summary_signature">
217
+
218
+ <a href="#format_query_param-instance_method" title="#format_query_param (instance method)">#<strong>format_query_param</strong>(value) &#x21d2; String<sup>?</sup> </a>
219
+
220
+
221
+
222
+ </span>
223
+
224
+
225
+
226
+
227
+
228
+
229
+
230
+
231
+
232
+ <span class="summary_desc"><div class='inline'>
233
+ <p>Formats a query parameter value for API requests.</p>
234
+ </div></span>
235
+
236
+ </li>
237
+
238
+
239
+ <li class="public ">
240
+ <span class="summary_signature">
241
+
242
+ <a href="#parse_timestamp-instance_method" title="#parse_timestamp (instance method)">#<strong>parse_timestamp</strong>(datetime_str) &#x21d2; DateTime<sup>?</sup> </a>
243
+
244
+
245
+
246
+ </span>
247
+
248
+
249
+
250
+
251
+
252
+
253
+
254
+
255
+
256
+ <span class="summary_desc"><div class='inline'>
257
+ <p>Safely parses a timestamp string.</p>
258
+ </div></span>
259
+
260
+ </li>
261
+
262
+
263
+ <li class="public ">
264
+ <span class="summary_signature">
265
+
266
+ <a href="#safe_float-instance_method" title="#safe_float (instance method)">#<strong>safe_float</strong>(value) &#x21d2; Float<sup>?</sup> </a>
267
+
268
+
269
+
270
+ </span>
271
+
272
+
273
+
274
+
275
+
276
+
277
+
278
+
279
+
280
+ <span class="summary_desc"><div class='inline'>
281
+ <p>Safely converts a value to a float.</p>
282
+ </div></span>
283
+
284
+ </li>
285
+
286
+
287
+ <li class="public ">
288
+ <span class="summary_signature">
289
+
290
+ <a href="#safe_integer-instance_method" title="#safe_integer (instance method)">#<strong>safe_integer</strong>(value) &#x21d2; Integer<sup>?</sup> </a>
291
+
292
+
293
+
294
+ </span>
295
+
296
+
297
+
298
+
299
+
300
+
301
+
302
+
303
+
304
+ <span class="summary_desc"><div class='inline'>
305
+ <p>Safely converts a value to an integer.</p>
306
+ </div></span>
307
+
308
+ </li>
309
+
310
+
311
+ </ul>
312
+
313
+
314
+
315
+
316
+ <div id="instance_method_details" class="method_details_list">
317
+ <h2>Instance Method Details</h2>
318
+
319
+
320
+ <div class="method_details first">
321
+ <h3 class="signature first" id="batch_dates-instance_method">
322
+
323
+ #<strong>batch_dates</strong>(start_date, end_date) &#x21d2; <tt>Array&lt;Array&lt;Date&gt;&gt;</tt>
324
+
325
+
326
+
327
+
328
+
329
+ </h3><div class="docstring">
330
+ <div class="discussion">
331
+
332
+ <p>Splits a date range into yearly chunks.</p>
333
+
334
+
335
+ </div>
336
+ </div>
337
+ <div class="tags">
338
+
339
+ <div class="examples">
340
+ <h4 class="tag_title">Examples:</h4>
341
+
342
+
343
+ <h5 class="example_title"><div class='inline'>
344
+ <p>Split a multi-year range</p>
345
+ </div></h5>
346
+
347
+ <pre class="example code"><code><span class='id identifier rubyid_batch_dates'>batch_dates</span><span class='lparen'>(</span><span class='const'>Date</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='int'>2020</span><span class='comma'>,</span><span class='int'>1</span><span class='comma'>,</span><span class='int'>1</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='const'>Date</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='int'>2022</span><span class='comma'>,</span><span class='int'>6</span><span class='comma'>,</span><span class='int'>30</span><span class='rparen'>)</span><span class='rparen'>)</span>
348
+ <span class='comment'>#=&gt; [[2020-01-01, 2020-12-31], [2021-01-01, 2021-12-31], [2022-01-01, 2022-06-30]]</span></code></pre>
349
+
350
+ </div>
351
+ <p class="tag_title">Parameters:</p>
352
+ <ul class="param">
353
+
354
+ <li>
355
+
356
+ <span class='name'>start_date</span>
357
+
358
+
359
+ <span class='type'>(<tt>Date</tt>, <tt>nil</tt>)</span>
360
+
361
+
362
+
363
+ &mdash;
364
+ <div class='inline'>
365
+ <p>Beginning of the date range</p>
366
+ </div>
367
+
368
+ </li>
369
+
370
+ <li>
371
+
372
+ <span class='name'>end_date</span>
373
+
374
+
375
+ <span class='type'>(<tt>Date</tt>, <tt>nil</tt>)</span>
376
+
377
+
378
+
379
+ &mdash;
380
+ <div class='inline'>
381
+ <p>End of the date range</p>
382
+ </div>
383
+
384
+ </li>
385
+
386
+ </ul>
387
+
388
+ <p class="tag_title">Returns:</p>
389
+ <ul class="return">
390
+
391
+ <li>
392
+
393
+
394
+ <span class='type'>(<tt>Array&lt;Array&lt;Date&gt;&gt;</tt>)</span>
395
+
396
+
397
+
398
+ &mdash;
399
+ <div class='inline'>
400
+ <p>Array of date pairs representing yearly chunks</p>
401
+ </div>
402
+
403
+ </li>
404
+
405
+ </ul>
406
+
407
+ </div><table class="source_code">
408
+ <tr>
409
+ <td>
410
+ <pre class="lines">
411
+
412
+
413
+ 17
414
+ 18
415
+ 19
416
+ 20
417
+ 21
418
+ 22
419
+ 23
420
+ 24
421
+ 25
422
+ 26
423
+ 27
424
+ 28
425
+ 29
426
+ 30
427
+ 31
428
+ 32
429
+ 33
430
+ 34
431
+ 35
432
+ 36</pre>
433
+ </td>
434
+ <td>
435
+ <pre class="code"><span class="info file"># File 'lib/cdss/utils.rb', line 17</span>
436
+
437
+ <span class='kw'>def</span> <span class='id identifier rubyid_batch_dates'>batch_dates</span><span class='lparen'>(</span><span class='id identifier rubyid_start_date'>start_date</span><span class='comma'>,</span> <span class='id identifier rubyid_end_date'>end_date</span><span class='rparen'>)</span>
438
+ <span class='id identifier rubyid_start_date'>start_date</span> <span class='op'>||=</span> <span class='const'>Date</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='int'>1900</span><span class='comma'>,</span> <span class='int'>1</span><span class='comma'>,</span> <span class='int'>1</span><span class='rparen'>)</span>
439
+ <span class='id identifier rubyid_end_date'>end_date</span> <span class='op'>||=</span> <span class='const'>Date</span><span class='period'>.</span><span class='id identifier rubyid_today'>today</span>
440
+ <span class='id identifier rubyid_start_year'>start_year</span> <span class='op'>=</span> <span class='id identifier rubyid_start_date'>start_date</span><span class='period'>.</span><span class='id identifier rubyid_year'>year</span>
441
+ <span class='id identifier rubyid_end_year'>end_year</span> <span class='op'>=</span> <span class='id identifier rubyid_end_date'>end_date</span><span class='period'>.</span><span class='id identifier rubyid_year'>year</span>
442
+ <span class='kw'>if</span> <span class='id identifier rubyid_start_year'>start_year</span> <span class='op'>==</span> <span class='id identifier rubyid_end_year'>end_year</span>
443
+ <span class='lbracket'>[</span><span class='lbracket'>[</span><span class='id identifier rubyid_start_date'>start_date</span><span class='comma'>,</span> <span class='id identifier rubyid_end_date'>end_date</span><span class='rbracket'>]</span><span class='rbracket'>]</span>
444
+ <span class='kw'>else</span>
445
+ <span class='id identifier rubyid_dates'>dates</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
446
+ <span class='comment'># First year
447
+ </span> <span class='id identifier rubyid_dates'>dates</span> <span class='op'>&lt;&lt;</span> <span class='lbracket'>[</span><span class='id identifier rubyid_start_date'>start_date</span><span class='comma'>,</span> <span class='const'>Date</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_start_year'>start_year</span><span class='comma'>,</span> <span class='int'>12</span><span class='comma'>,</span> <span class='int'>31</span><span class='rparen'>)</span><span class='rbracket'>]</span>
448
+ <span class='comment'># Middle years
449
+ </span> <span class='lparen'>(</span><span class='lparen'>(</span><span class='id identifier rubyid_start_year'>start_year</span> <span class='op'>+</span> <span class='int'>1</span><span class='rparen'>)</span><span class='op'>...</span><span class='id identifier rubyid_end_year'>end_year</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_year'>year</span><span class='op'>|</span>
450
+ <span class='id identifier rubyid_dates'>dates</span> <span class='op'>&lt;&lt;</span> <span class='lbracket'>[</span><span class='const'>Date</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_year'>year</span><span class='comma'>,</span> <span class='int'>1</span><span class='comma'>,</span> <span class='int'>1</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='const'>Date</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_year'>year</span><span class='comma'>,</span> <span class='int'>12</span><span class='comma'>,</span> <span class='int'>31</span><span class='rparen'>)</span><span class='rbracket'>]</span>
451
+ <span class='kw'>end</span>
452
+ <span class='comment'># Last year
453
+ </span> <span class='id identifier rubyid_dates'>dates</span> <span class='op'>&lt;&lt;</span> <span class='lbracket'>[</span><span class='const'>Date</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_end_year'>end_year</span><span class='comma'>,</span> <span class='int'>1</span><span class='comma'>,</span> <span class='int'>1</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_end_date'>end_date</span><span class='rbracket'>]</span>
454
+ <span class='id identifier rubyid_dates'>dates</span>
455
+ <span class='kw'>end</span>
456
+ <span class='kw'>end</span></pre>
457
+ </td>
458
+ </tr>
459
+ </table>
460
+ </div>
461
+
462
+ <div class="method_details ">
463
+ <h3 class="signature " id="build_query-instance_method">
464
+
465
+ #<strong>build_query</strong>(params = {}, encode: false) &#x21d2; <tt>Hash</tt>
466
+
467
+
468
+
469
+
470
+
471
+ </h3><div class="docstring">
472
+ <div class="discussion">
473
+
474
+ <p>Builds a query hash for API requests.</p>
475
+
476
+
477
+ </div>
478
+ </div>
479
+ <div class="tags">
480
+
481
+ <div class="examples">
482
+ <h4 class="tag_title">Examples:</h4>
483
+
484
+
485
+ <h5 class="example_title"><div class='inline'>
486
+ <p>Build a simple query</p>
487
+ </div></h5>
488
+
489
+ <pre class="example code"><code><span class='id identifier rubyid_build_query'>build_query</span><span class='lparen'>(</span><span class='lbrace'>{</span> <span class='label'>name:</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>test</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='label'>id:</span> <span class='int'>123</span> <span class='rbrace'>}</span><span class='rparen'>)</span>
490
+ <span class='comment'>#=&gt; { format: &quot;json&quot;, name: &quot;test&quot;, id: &quot;123&quot; }</span></code></pre>
491
+
492
+ </div>
493
+ <p class="tag_title">Parameters:</p>
494
+ <ul class="param">
495
+
496
+ <li>
497
+
498
+ <span class='name'>params</span>
499
+
500
+
501
+ <span class='type'>(<tt>Hash</tt>)</span>
502
+
503
+
504
+ <em class="default">(defaults to: <tt>{}</tt>)</em>
505
+
506
+
507
+ &mdash;
508
+ <div class='inline'>
509
+ <p>Query parameters to include</p>
510
+ </div>
511
+
512
+ </li>
513
+
514
+ <li>
515
+
516
+ <span class='name'>encode</span>
517
+
518
+
519
+ <span class='type'>(<tt>Boolean</tt>)</span>
520
+
521
+
522
+ <em class="default">(defaults to: <tt>false</tt>)</em>
523
+
524
+
525
+ &mdash;
526
+ <div class='inline'>
527
+ <p>Whether to URL encode parameter values</p>
528
+ </div>
529
+
530
+ </li>
531
+
532
+ </ul>
533
+
534
+ <p class="tag_title">Returns:</p>
535
+ <ul class="return">
536
+
537
+ <li>
538
+
539
+
540
+ <span class='type'>(<tt>Hash</tt>)</span>
541
+
542
+
543
+
544
+ &mdash;
545
+ <div class='inline'>
546
+ <p>Query hash with formatted parameters</p>
547
+ </div>
548
+
549
+ </li>
550
+
551
+ </ul>
552
+
553
+ </div><table class="source_code">
554
+ <tr>
555
+ <td>
556
+ <pre class="lines">
557
+
558
+
559
+ 59
560
+ 60
561
+ 61
562
+ 62
563
+ 63
564
+ 64
565
+ 65
566
+ 66
567
+ 67
568
+ 68
569
+ 69
570
+ 70</pre>
571
+ </td>
572
+ <td>
573
+ <pre class="code"><span class="info file"># File 'lib/cdss/utils.rb', line 59</span>
574
+
575
+ <span class='kw'>def</span> <span class='id identifier rubyid_build_query'>build_query</span><span class='lparen'>(</span><span class='id identifier rubyid_params'>params</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='comma'>,</span> <span class='label'>encode:</span> <span class='kw'>false</span><span class='rparen'>)</span>
576
+ <span class='id identifier rubyid_base_query'>base_query</span> <span class='op'>=</span> <span class='lbrace'>{</span>
577
+ <span class='label'>format:</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>json</span><span class='tstring_end'>&quot;</span></span>
578
+ <span class='rbrace'>}</span>
579
+ <span class='id identifier rubyid_params'>params</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='op'>|</span>
580
+ <span class='id identifier rubyid_formatted_value'>formatted_value</span> <span class='op'>=</span> <span class='id identifier rubyid_format_query_param'>format_query_param</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
581
+ <span class='kw'>if</span> <span class='id identifier rubyid_formatted_value'>formatted_value</span>
582
+ <span class='id identifier rubyid_base_query'>base_query</span><span class='lbracket'>[</span><span class='id identifier rubyid_key'>key</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_encode'>encode</span> <span class='op'>?</span> <span class='const'>URI</span><span class='period'>.</span><span class='id identifier rubyid_encode_www_form_component'>encode_www_form_component</span><span class='lparen'>(</span><span class='id identifier rubyid_formatted_value'>formatted_value</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='id identifier rubyid_formatted_value'>formatted_value</span>
583
+ <span class='kw'>end</span>
584
+ <span class='kw'>end</span>
585
+ <span class='id identifier rubyid_base_query'>base_query</span>
586
+ <span class='kw'>end</span></pre>
587
+ </td>
588
+ </tr>
589
+ </table>
590
+ </div>
591
+
592
+ <div class="method_details ">
593
+ <h3 class="signature " id="fetch_paginated_data-instance_method">
594
+
595
+ #<strong>fetch_paginated_data</strong>(endpoint:, query:) {|Hash| ... } &#x21d2; <tt>Array</tt>
596
+
597
+
598
+
599
+
600
+
601
+ </h3><div class="docstring">
602
+ <div class="discussion">
603
+
604
+ <p>Fetches all pages of data from a paginated API endpoint.</p>
605
+
606
+
607
+ </div>
608
+ </div>
609
+ <div class="tags">
610
+
611
+ <div class="examples">
612
+ <h4 class="tag_title">Examples:</h4>
613
+
614
+
615
+ <h5 class="example_title"><div class='inline'>
616
+ <p>Fetch paginated data</p>
617
+ </div></h5>
618
+
619
+ <pre class="example code"><code><span class='id identifier rubyid_fetch_paginated_data'>fetch_paginated_data</span><span class='lparen'>(</span><span class='label'>endpoint:</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>/api/data</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='label'>query:</span> <span class='lbrace'>{</span> <span class='label'>type:</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>test</span><span class='tstring_end'>&quot;</span></span> <span class='rbrace'>}</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_data'>data</span><span class='op'>|</span>
620
+ <span class='id identifier rubyid_process_data'>process_data</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
621
+ <span class='kw'>end</span></code></pre>
622
+
623
+ </div>
624
+ <p class="tag_title">Parameters:</p>
625
+ <ul class="param">
626
+
627
+ <li>
628
+
629
+ <span class='name'>endpoint</span>
630
+
631
+
632
+ <span class='type'>(<tt>String</tt>)</span>
633
+
634
+
635
+
636
+ &mdash;
637
+ <div class='inline'>
638
+ <p>API endpoint path</p>
639
+ </div>
640
+
641
+ </li>
642
+
643
+ <li>
644
+
645
+ <span class='name'>query</span>
646
+
647
+
648
+ <span class='type'>(<tt>Hash</tt>)</span>
649
+
650
+
651
+
652
+ &mdash;
653
+ <div class='inline'>
654
+ <p>Query parameters for the request</p>
655
+ </div>
656
+
657
+ </li>
658
+
659
+ </ul>
660
+
661
+ <p class="tag_title">Yields:</p>
662
+ <ul class="yield">
663
+
664
+ <li>
665
+
666
+
667
+ <span class='type'>(<tt>Hash</tt>)</span>
668
+
669
+
670
+
671
+ &mdash;
672
+ <div class='inline'>
673
+ <p>Block to process each page of response data</p>
674
+ </div>
675
+
676
+ </li>
677
+
678
+ </ul>
679
+ <p class="tag_title">Yield Returns:</p>
680
+ <ul class="yieldreturn">
681
+
682
+ <li>
683
+
684
+
685
+ <span class='type'>(<tt>Array</tt>)</span>
686
+
687
+
688
+
689
+ &mdash;
690
+ <div class='inline'>
691
+ <p>Processed records from the response</p>
692
+ </div>
693
+
694
+ </li>
695
+
696
+ </ul>
697
+ <p class="tag_title">Returns:</p>
698
+ <ul class="return">
699
+
700
+ <li>
701
+
702
+
703
+ <span class='type'>(<tt>Array</tt>)</span>
704
+
705
+
706
+
707
+ &mdash;
708
+ <div class='inline'>
709
+ <p>Combined results from all pages</p>
710
+ </div>
711
+
712
+ </li>
713
+
714
+ </ul>
715
+
716
+ </div><table class="source_code">
717
+ <tr>
718
+ <td>
719
+ <pre class="lines">
720
+
721
+
722
+ 133
723
+ 134
724
+ 135
725
+ 136
726
+ 137
727
+ 138
728
+ 139
729
+ 140
730
+ 141
731
+ 142
732
+ 143
733
+ 144
734
+ 145
735
+ 146
736
+ 147
737
+ 148
738
+ 149
739
+ 150</pre>
740
+ </td>
741
+ <td>
742
+ <pre class="code"><span class="info file"># File 'lib/cdss/utils.rb', line 133</span>
743
+
744
+ <span class='kw'>def</span> <span class='id identifier rubyid_fetch_paginated_data'>fetch_paginated_data</span><span class='lparen'>(</span><span class='label'>endpoint:</span><span class='comma'>,</span> <span class='label'>query:</span><span class='rparen'>)</span>
745
+ <span class='id identifier rubyid_page_size'>page_size</span> <span class='op'>=</span> <span class='int'>50_000</span>
746
+ <span class='id identifier rubyid_page_index'>page_index</span> <span class='op'>=</span> <span class='int'>1</span>
747
+ <span class='id identifier rubyid_results'>results</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
748
+ <span class='id identifier rubyid_loop'>loop</span> <span class='kw'>do</span>
749
+ <span class='id identifier rubyid_query'>query</span> <span class='op'>=</span> <span class='id identifier rubyid_query'>query</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='label'>pageSize:</span> <span class='id identifier rubyid_page_size'>page_size</span><span class='comma'>,</span> <span class='label'>pageIndex:</span> <span class='id identifier rubyid_page_index'>page_index</span><span class='rparen'>)</span>
750
+ <span class='id identifier rubyid_response'>response</span> <span class='op'>=</span> <span class='id identifier rubyid_get'>get</span><span class='lparen'>(</span><span class='id identifier rubyid_endpoint'>endpoint</span><span class='comma'>,</span> <span class='label'>query:</span> <span class='id identifier rubyid_query'>query</span><span class='rparen'>)</span>
751
+ <span class='id identifier rubyid_data'>data</span> <span class='op'>=</span> <span class='id identifier rubyid_handle_response'>handle_response</span><span class='lparen'>(</span><span class='id identifier rubyid_response'>response</span><span class='rparen'>)</span>
752
+ <span class='id identifier rubyid_records'>records</span> <span class='op'>=</span> <span class='kw'>yield</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
753
+ <span class='kw'>break</span> <span class='kw'>if</span> <span class='id identifier rubyid_records'>records</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
754
+
755
+ <span class='id identifier rubyid_results'>results</span><span class='period'>.</span><span class='id identifier rubyid_concat'>concat</span><span class='lparen'>(</span><span class='id identifier rubyid_records'>records</span><span class='rparen'>)</span>
756
+ <span class='kw'>break</span> <span class='kw'>if</span> <span class='id identifier rubyid_records'>records</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span> <span class='op'>&lt;</span> <span class='id identifier rubyid_page_size'>page_size</span>
757
+
758
+ <span class='id identifier rubyid_page_index'>page_index</span> <span class='op'>+=</span> <span class='int'>1</span>
759
+ <span class='kw'>end</span>
760
+ <span class='id identifier rubyid_results'>results</span>
761
+ <span class='kw'>end</span></pre>
762
+ </td>
763
+ </tr>
764
+ </table>
765
+ </div>
766
+
767
+ <div class="method_details ">
768
+ <h3 class="signature " id="format_date-instance_method">
769
+
770
+ #<strong>format_date</strong>(date, special_format: false) &#x21d2; <tt>String</tt><sup>?</sup>
771
+
772
+
773
+
774
+
775
+
776
+ </h3><div class="docstring">
777
+ <div class="discussion">
778
+
779
+ <p>Formats a date for API requests.</p>
780
+
781
+
782
+ </div>
783
+ </div>
784
+ <div class="tags">
785
+
786
+ <div class="examples">
787
+ <h4 class="tag_title">Examples:</h4>
788
+
789
+
790
+ <h5 class="example_title"><div class='inline'>
791
+ <p>Format a date</p>
792
+ </div></h5>
793
+
794
+ <pre class="example code"><code><span class='id identifier rubyid_format_date'>format_date</span><span class='lparen'>(</span><span class='const'>Date</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='int'>2023</span><span class='comma'>,</span><span class='int'>1</span><span class='comma'>,</span><span class='int'>1</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='comment'>#=&gt; &quot;01-01-2023&quot;</span></code></pre>
795
+
796
+ </div>
797
+ <p class="tag_title">Parameters:</p>
798
+ <ul class="param">
799
+
800
+ <li>
801
+
802
+ <span class='name'>date</span>
803
+
804
+
805
+ <span class='type'>(<tt>Date</tt>)</span>
806
+
807
+
808
+
809
+ &mdash;
810
+ <div class='inline'>
811
+ <p>The date to format</p>
812
+ </div>
813
+
814
+ </li>
815
+
816
+ <li>
817
+
818
+ <span class='name'>special_format</span>
819
+
820
+
821
+ <span class='type'>(<tt>Boolean</tt>)</span>
822
+
823
+
824
+ <em class="default">(defaults to: <tt>false</tt>)</em>
825
+
826
+
827
+ &mdash;
828
+ <div class='inline'>
829
+ <p>Whether to use forward slashes instead of hyphens</p>
830
+ </div>
831
+
832
+ </li>
833
+
834
+ </ul>
835
+
836
+ <p class="tag_title">Returns:</p>
837
+ <ul class="return">
838
+
839
+ <li>
840
+
841
+
842
+ <span class='type'>(<tt>String</tt>, <tt>nil</tt>)</span>
843
+
844
+
845
+
846
+ &mdash;
847
+ <div class='inline'>
848
+ <p>Formatted date string or nil if input is nil</p>
849
+ </div>
850
+
851
+ </li>
852
+
853
+ </ul>
854
+
855
+ </div><table class="source_code">
856
+ <tr>
857
+ <td>
858
+ <pre class="lines">
859
+
860
+
861
+ 79
862
+ 80
863
+ 81
864
+ 82
865
+ 83
866
+ 84</pre>
867
+ </td>
868
+ <td>
869
+ <pre class="code"><span class="info file"># File 'lib/cdss/utils.rb', line 79</span>
870
+
871
+ <span class='kw'>def</span> <span class='id identifier rubyid_format_date'>format_date</span><span class='lparen'>(</span><span class='id identifier rubyid_date'>date</span><span class='comma'>,</span> <span class='label'>special_format:</span> <span class='kw'>false</span><span class='rparen'>)</span>
872
+ <span class='kw'>return</span> <span class='kw'>nil</span> <span class='kw'>unless</span> <span class='id identifier rubyid_date'>date</span>
873
+
874
+ <span class='id identifier rubyid_date'>date</span> <span class='op'>=</span> <span class='id identifier rubyid_date'>date</span><span class='period'>.</span><span class='id identifier rubyid_strftime'>strftime</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>%m-%d-%Y</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
875
+ <span class='id identifier rubyid_special_format'>special_format</span> <span class='op'>?</span> <span class='id identifier rubyid_date'>date</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>-</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>%2F</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='op'>:</span> <span class='id identifier rubyid_date'>date</span>
876
+ <span class='kw'>end</span></pre>
877
+ </td>
878
+ </tr>
879
+ </table>
880
+ </div>
881
+
882
+ <div class="method_details ">
883
+ <h3 class="signature " id="format_query_param-instance_method">
884
+
885
+ #<strong>format_query_param</strong>(value) &#x21d2; <tt>String</tt><sup>?</sup>
886
+
887
+
888
+
889
+
890
+
891
+ </h3><div class="docstring">
892
+ <div class="discussion">
893
+
894
+ <p>Formats a query parameter value for API requests.</p>
895
+
896
+
897
+ </div>
898
+ </div>
899
+ <div class="tags">
900
+
901
+ <div class="examples">
902
+ <h4 class="tag_title">Examples:</h4>
903
+
904
+
905
+ <h5 class="example_title"><div class='inline'>
906
+ <p>Format an array parameter</p>
907
+ </div></h5>
908
+
909
+ <pre class="example code"><code><span class='id identifier rubyid_format_query_param'>format_query_param</span><span class='lparen'>(</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>a</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>b</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='comment'>#=&gt; &quot;a,b&quot;</span></code></pre>
910
+
911
+ </div>
912
+ <p class="tag_title">Parameters:</p>
913
+ <ul class="param">
914
+
915
+ <li>
916
+
917
+ <span class='name'>value</span>
918
+
919
+
920
+ <span class='type'>(<tt>Object</tt>)</span>
921
+
922
+
923
+
924
+ &mdash;
925
+ <div class='inline'>
926
+ <p>The value to format</p>
927
+ </div>
928
+
929
+ </li>
930
+
931
+ </ul>
932
+
933
+ <p class="tag_title">Returns:</p>
934
+ <ul class="return">
935
+
936
+ <li>
937
+
938
+
939
+ <span class='type'>(<tt>String</tt>, <tt>nil</tt>)</span>
940
+
941
+
942
+
943
+ &mdash;
944
+ <div class='inline'>
945
+ <p>Formatted value or nil if input is nil</p>
946
+ </div>
947
+
948
+ </li>
949
+
950
+ </ul>
951
+
952
+ </div><table class="source_code">
953
+ <tr>
954
+ <td>
955
+ <pre class="lines">
956
+
957
+
958
+ 44
959
+ 45
960
+ 46
961
+ 47
962
+ 48
963
+ 49</pre>
964
+ </td>
965
+ <td>
966
+ <pre class="code"><span class="info file"># File 'lib/cdss/utils.rb', line 44</span>
967
+
968
+ <span class='kw'>def</span> <span class='id identifier rubyid_format_query_param'>format_query_param</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
969
+ <span class='kw'>return</span> <span class='kw'>nil</span> <span class='kw'>if</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
970
+ <span class='kw'>return</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>,</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Array</span><span class='rparen'>)</span>
971
+
972
+ <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span>
973
+ <span class='kw'>end</span></pre>
974
+ </td>
975
+ </tr>
976
+ </table>
977
+ </div>
978
+
979
+ <div class="method_details ">
980
+ <h3 class="signature " id="parse_timestamp-instance_method">
981
+
982
+ #<strong>parse_timestamp</strong>(datetime_str) &#x21d2; <tt>DateTime</tt><sup>?</sup>
983
+
984
+
985
+
986
+
987
+
988
+ </h3><div class="docstring">
989
+ <div class="discussion">
990
+
991
+ <p>Safely parses a timestamp string.</p>
992
+
993
+
994
+ </div>
995
+ </div>
996
+ <div class="tags">
997
+
998
+ <div class="examples">
999
+ <h4 class="tag_title">Examples:</h4>
1000
+
1001
+
1002
+ <h5 class="example_title"><div class='inline'>
1003
+ <p>Parse a timestamp</p>
1004
+ </div></h5>
1005
+
1006
+ <pre class="example code"><code><span class='id identifier rubyid_parse_timestamp'>parse_timestamp</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>2023-01-01 12:00:00</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span></code></pre>
1007
+
1008
+ </div>
1009
+ <p class="tag_title">Parameters:</p>
1010
+ <ul class="param">
1011
+
1012
+ <li>
1013
+
1014
+ <span class='name'>datetime_str</span>
1015
+
1016
+
1017
+ <span class='type'>(<tt>String</tt>)</span>
1018
+
1019
+
1020
+
1021
+ &mdash;
1022
+ <div class='inline'>
1023
+ <p>Timestamp string to parse</p>
1024
+ </div>
1025
+
1026
+ </li>
1027
+
1028
+ </ul>
1029
+
1030
+ <p class="tag_title">Returns:</p>
1031
+ <ul class="return">
1032
+
1033
+ <li>
1034
+
1035
+
1036
+ <span class='type'>(<tt>DateTime</tt>, <tt>nil</tt>)</span>
1037
+
1038
+
1039
+
1040
+ &mdash;
1041
+ <div class='inline'>
1042
+ <p>Parsed DateTime object or nil if parsing fails</p>
1043
+ </div>
1044
+
1045
+ </li>
1046
+
1047
+ </ul>
1048
+
1049
+ </div><table class="source_code">
1050
+ <tr>
1051
+ <td>
1052
+ <pre class="lines">
1053
+
1054
+
1055
+ 92
1056
+ 93
1057
+ 94
1058
+ 95
1059
+ 96</pre>
1060
+ </td>
1061
+ <td>
1062
+ <pre class="code"><span class="info file"># File 'lib/cdss/utils.rb', line 92</span>
1063
+
1064
+ <span class='kw'>def</span> <span class='id identifier rubyid_parse_timestamp'>parse_timestamp</span><span class='lparen'>(</span><span class='id identifier rubyid_datetime_str'>datetime_str</span><span class='rparen'>)</span>
1065
+ <span class='const'>DateTime</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_datetime_str'>datetime_str</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_datetime_str'>datetime_str</span>
1066
+ <span class='kw'>rescue</span> <span class='const'>ArgumentError</span>
1067
+ <span class='kw'>nil</span>
1068
+ <span class='kw'>end</span></pre>
1069
+ </td>
1070
+ </tr>
1071
+ </table>
1072
+ </div>
1073
+
1074
+ <div class="method_details ">
1075
+ <h3 class="signature " id="safe_float-instance_method">
1076
+
1077
+ #<strong>safe_float</strong>(value) &#x21d2; <tt>Float</tt><sup>?</sup>
1078
+
1079
+
1080
+
1081
+
1082
+
1083
+ </h3><div class="docstring">
1084
+ <div class="discussion">
1085
+
1086
+ <p>Safely converts a value to a float.</p>
1087
+
1088
+
1089
+ </div>
1090
+ </div>
1091
+ <div class="tags">
1092
+
1093
+ <div class="examples">
1094
+ <h4 class="tag_title">Examples:</h4>
1095
+
1096
+
1097
+ <h5 class="example_title"><div class='inline'>
1098
+ <p>Convert a string to float</p>
1099
+ </div></h5>
1100
+
1101
+ <pre class="example code"><code><span class='id identifier rubyid_safe_float'>safe_float</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>123.45</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='comment'>#=&gt; 123.45</span></code></pre>
1102
+
1103
+ </div>
1104
+ <p class="tag_title">Parameters:</p>
1105
+ <ul class="param">
1106
+
1107
+ <li>
1108
+
1109
+ <span class='name'>value</span>
1110
+
1111
+
1112
+ <span class='type'>(<tt>Object</tt>)</span>
1113
+
1114
+
1115
+
1116
+ &mdash;
1117
+ <div class='inline'>
1118
+ <p>Value to convert</p>
1119
+ </div>
1120
+
1121
+ </li>
1122
+
1123
+ </ul>
1124
+
1125
+ <p class="tag_title">Returns:</p>
1126
+ <ul class="return">
1127
+
1128
+ <li>
1129
+
1130
+
1131
+ <span class='type'>(<tt>Float</tt>, <tt>nil</tt>)</span>
1132
+
1133
+
1134
+
1135
+ &mdash;
1136
+ <div class='inline'>
1137
+ <p>Converted float or nil if conversion fails</p>
1138
+ </div>
1139
+
1140
+ </li>
1141
+
1142
+ </ul>
1143
+
1144
+ </div><table class="source_code">
1145
+ <tr>
1146
+ <td>
1147
+ <pre class="lines">
1148
+
1149
+
1150
+ 104
1151
+ 105
1152
+ 106
1153
+ 107
1154
+ 108</pre>
1155
+ </td>
1156
+ <td>
1157
+ <pre class="code"><span class="info file"># File 'lib/cdss/utils.rb', line 104</span>
1158
+
1159
+ <span class='kw'>def</span> <span class='id identifier rubyid_safe_float'>safe_float</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
1160
+ <span class='const'>Float</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
1161
+ <span class='kw'>rescue</span> <span class='const'>TypeError</span><span class='comma'>,</span> <span class='const'>ArgumentError</span>
1162
+ <span class='kw'>nil</span>
1163
+ <span class='kw'>end</span></pre>
1164
+ </td>
1165
+ </tr>
1166
+ </table>
1167
+ </div>
1168
+
1169
+ <div class="method_details ">
1170
+ <h3 class="signature " id="safe_integer-instance_method">
1171
+
1172
+ #<strong>safe_integer</strong>(value) &#x21d2; <tt>Integer</tt><sup>?</sup>
1173
+
1174
+
1175
+
1176
+
1177
+
1178
+ </h3><div class="docstring">
1179
+ <div class="discussion">
1180
+
1181
+ <p>Safely converts a value to an integer.</p>
1182
+
1183
+
1184
+ </div>
1185
+ </div>
1186
+ <div class="tags">
1187
+
1188
+ <div class="examples">
1189
+ <h4 class="tag_title">Examples:</h4>
1190
+
1191
+
1192
+ <h5 class="example_title"><div class='inline'>
1193
+ <p>Convert a string to integer</p>
1194
+ </div></h5>
1195
+
1196
+ <pre class="example code"><code><span class='id identifier rubyid_safe_integer'>safe_integer</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>123</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='comment'>#=&gt; 123</span></code></pre>
1197
+
1198
+ </div>
1199
+ <p class="tag_title">Parameters:</p>
1200
+ <ul class="param">
1201
+
1202
+ <li>
1203
+
1204
+ <span class='name'>value</span>
1205
+
1206
+
1207
+ <span class='type'>(<tt>Object</tt>)</span>
1208
+
1209
+
1210
+
1211
+ &mdash;
1212
+ <div class='inline'>
1213
+ <p>Value to convert</p>
1214
+ </div>
1215
+
1216
+ </li>
1217
+
1218
+ </ul>
1219
+
1220
+ <p class="tag_title">Returns:</p>
1221
+ <ul class="return">
1222
+
1223
+ <li>
1224
+
1225
+
1226
+ <span class='type'>(<tt>Integer</tt>, <tt>nil</tt>)</span>
1227
+
1228
+
1229
+
1230
+ &mdash;
1231
+ <div class='inline'>
1232
+ <p>Converted integer or nil if conversion fails</p>
1233
+ </div>
1234
+
1235
+ </li>
1236
+
1237
+ </ul>
1238
+
1239
+ </div><table class="source_code">
1240
+ <tr>
1241
+ <td>
1242
+ <pre class="lines">
1243
+
1244
+
1245
+ 116
1246
+ 117
1247
+ 118
1248
+ 119
1249
+ 120</pre>
1250
+ </td>
1251
+ <td>
1252
+ <pre class="code"><span class="info file"># File 'lib/cdss/utils.rb', line 116</span>
1253
+
1254
+ <span class='kw'>def</span> <span class='id identifier rubyid_safe_integer'>safe_integer</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
1255
+ <span class='const'>Integer</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
1256
+ <span class='kw'>rescue</span> <span class='const'>TypeError</span><span class='comma'>,</span> <span class='const'>ArgumentError</span>
1257
+ <span class='kw'>nil</span>
1258
+ <span class='kw'>end</span></pre>
1259
+ </td>
1260
+ </tr>
1261
+ </table>
1262
+ </div>
1263
+
1264
+ </div>
1265
+
1266
+ </div>
1267
+
1268
+ <div id="footer">
1269
+ Generated on Thu Feb 20 21:19:08 2025 by
1270
+ <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1271
+ 0.9.37 (ruby-3.2.2).
1272
+ </div>
1273
+
1274
+ </div>
1275
+ </body>
1276
+ </html>