Class: Hash

Inherits:
Object show all
Defined in:
opal/fron/core_ext/hash.rb

Overview

Hash

Instance Method Summary collapse

Instance Method Details

#deepDiff(other) ⇒ Hash

Produces a diff hash from self and the other hash

Parameters:

  • other (Hash)

    The other hash

Returns:

  • (Hash)

    The difference from the other hash


28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'opal/fron/core_ext/hash.rb', line 28

def deepDiff(other)
  (keys + other.keys).uniq.each_with_object({}) do |key, diff|
    selfKey  = self[key]
    otherKey = other[key]
    next if selfKey == otherKey
    if selfKey.respond_to?(:deepDiff) && otherKey.respond_to?(:deepDiff)
      diff[key] = selfKey.deepDiff(otherKey)
    else
      diff[key] = [selfKey, otherKey]
    end
    diff
  end
end

#toFormDataFormData

Converts the hash into a form data object

Returns:

  • (FormData)

    The native form data object


15
16
17
18
19
20
21
# File 'opal/fron/core_ext/hash.rb', line 15

def toFormData
  formData = `new FormData()`
  each do |key, value|
    `#{formData}.append(#{key},#{value})`
  end
  formData
end

#toQueryStringString

Converts the hash into an url encoded query string

Returns:

  • (String)

    the query string


6
7
8
9
10
# File 'opal/fron/core_ext/hash.rb', line 6

def toQueryString
  map do |key, value|
    `encodeURIComponent(#{key})+"="+encodeURIComponent(#{value})`
  end.join '&'
end