Class: Hash

Inherits:
Object show all
Defined in:
lib/tektite_ruby_utils/present.rb

Overview

Extend Hash with some helper methods.

Instance Method Summary collapse

Instance Method Details

#all_present?Boolean

Returns true if all values are present, otherwise false

Returns:

  • (Boolean)


108
109
110
111
112
113
# File 'lib/tektite_ruby_utils/present.rb', line 108

def all_present?
  each do |_key, value|
    return false if value.nil?
  end
  true
end

#each_present?Boolean

Returns a hash with the values of the original hash replaced with true if the value is present and false if nil.

Returns:

  • (Boolean)


117
118
119
120
121
122
123
# File 'lib/tektite_ruby_utils/present.rb', line 117

def each_present?
  result = {}
  each do |key, value|
    result[key] = value.present?
  end
  result
end

#mask_presentObject

Returns a hash with non-nil values of the original hash replaced with present.



127
128
129
130
131
132
133
# File 'lib/tektite_ruby_utils/present.rb', line 127

def mask_present
  result = {}
  each do |key, value|
    result[key] = value.present? ? present : nil
  end
  result
end