Module: WAB::Utils
- Defined in:
- lib/wab/utils.rb
Constant Summary collapse
- UUID_REGEX =
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.freeze
- TIME_REGEX =
/^\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}\.\d{9}Z$/.freeze
Class Method Summary collapse
-
.populated_hash?(obj) ⇒ Boolean
Determine if a given object is not an empty Hash.
-
.pre_24_fixnum?(obj) ⇒ Boolean
Detect if ‘obj` is an instance of `Fixnum` from Ruby older than 2.4.x.
- .ruby_series ⇒ Object
-
.uuid_format?(str) ⇒ Boolean
Detect if given string matches ISO/IEC UUID format: “123e4567-e89b-12d3-a456-426655440000”.
-
.wab_time_format?(str) ⇒ Boolean
Detect if given string matches a Time format as encoded by WAB components: “2017-09-01T12:45:15.123456789Z”.
Class Method Details
.populated_hash?(obj) ⇒ Boolean
Determine if a given object is not an empty Hash
17 18 19 |
# File 'lib/wab/utils.rb', line 17 def populated_hash?(obj) obj.is_a?(Hash) && !obj.empty? end |
.pre_24_fixnum?(obj) ⇒ Boolean
Detect if ‘obj` is an instance of `Fixnum` from Ruby older than 2.4.x
12 13 14 |
# File 'lib/wab/utils.rb', line 12 def pre_24_fixnum?(obj) 24 > ruby_series && obj.is_a?(Fixnum) end |
.ruby_series ⇒ Object
7 8 9 |
# File 'lib/wab/utils.rb', line 7 def ruby_series RbConfig::CONFIG.values_at('MAJOR', 'MINOR').join.to_i end |
.uuid_format?(str) ⇒ Boolean
Detect if given string matches ISO/IEC UUID format: “123e4567-e89b-12d3-a456-426655440000”
23 24 25 26 |
# File 'lib/wab/utils.rb', line 23 def uuid_format?(str) return false unless 36 == str.length UUID_REGEX === str end |
.wab_time_format?(str) ⇒ Boolean
Detect if given string matches a Time format as encoded by WAB components: “2017-09-01T12:45:15.123456789Z”
30 31 32 33 |
# File 'lib/wab/utils.rb', line 30 def wab_time_format?(str) return false unless 30 == str.length TIME_REGEX === str end |