class Helpers

Routine methods for DanarchySys

Public Class Methods

array_to_numhash(array) click to toggle source
# File lib/danarchy_sys/helpers.rb, line 4
def self.array_to_numhash(array)
  numbered_hash = {}
  
  array.each.with_index(1) do |item, id|
    numbered_hash[id] = item
  end

  numbered_hash
end
check_nested_hash_value(hash, key, value) click to toggle source
# File lib/danarchy_sys/helpers.rb, line 56
def self.check_nested_hash_value(hash, key, value)
  check = false

  hash.each_value do |val|
    check = true if val[key].end_with?(value)
  end

  check
end
hash_largest_key(hash) click to toggle source
# File lib/danarchy_sys/helpers.rb, line 40
def self.hash_largest_key(hash)
  hash.keys.map(&:to_s).max_by(&:size)
end
hash_largest_nested_key(hash) click to toggle source
# File lib/danarchy_sys/helpers.rb, line 48
def self.hash_largest_nested_key(hash)
  hash.each_value.flat_map(&:keys).max_by(&:size)
end
hash_largest_nested_value(hash) click to toggle source
# File lib/danarchy_sys/helpers.rb, line 52
def self.hash_largest_nested_value(hash)
  hash.each_value.flat_map(&:values).max_by(&:size)
end
hash_largest_value(hash) click to toggle source
# File lib/danarchy_sys/helpers.rb, line 44
def self.hash_largest_value(hash)
  hash.values.map(&:to_s).max_by(&:size)
end
hash_to_numhash(hash) click to toggle source
# File lib/danarchy_sys/helpers.rb, line 14
def self.hash_to_numhash(hash)
  numbered_hash = {}

  hash.map.with_index(1) do | (k, v), index |
    numbered_hash[index] = {k => v}
  end

  numbered_hash
end
object_to_hash(object) click to toggle source
# File lib/danarchy_sys/helpers.rb, line 24
def self.object_to_hash(object)
  return nil if !object
  object.all_attributes
end
objects_to_numhash(objects) click to toggle source
# File lib/danarchy_sys/helpers.rb, line 29
def self.objects_to_numhash(objects)
  return nil if !objects
  numbered_object_hash = {}

  objects.map.with_index(1) do | obj, index |
    numbered_object_hash[index] = obj.all_attributes
  end

  numbered_object_hash
end