module Flatten

Provides smash-key access to a Hash.

{'foo'=>{'bar'=>'bingo'}}.smash #=> {'foo.bar'=>'bingo'} {'foo.bar'=>'bingo'}.unsmash => {'foo'=>{'bar'=>'bingo'}}

Constants

DEFAULT_SEPARATOR

The default separator, used if not specified in command's options hash.

VERSION

Public Instance Methods

smash(options = {}) click to toggle source

Returns a smash version of self using the options provided.

@param options [Hash<Symbol,Object>] @option options [String] :separator @option options [String] :prefix @option options [Boolean,:zero_pad] :smash_array (false)

truthy values will cause arrays to be smashd by index and decended into.
:zero_pad causes indexes to be zero-padded to make them sort lexically.

@return [Hash<String,Object>]

# File lib/flatten.rb, line 30
def smash(options = {})
        Flatten.smash(self, options)
end
smash!(options = {}) click to toggle source

Replaces self with smash version of itself.

@param options (see smash) @return [Hash<String,Object>]

# File lib/flatten.rb, line 38
def smash!(options = {})
        self.replace(smash, options)
end
smash_each(options = {}, &block) click to toggle source

Used internally by both Flatten::Utility#smash and Flatten::Utility#unsmash

@overload smash_each(options = {}, &block)

Yields once per key in smash version of itself.
@param options (see #smash)
@yieldparam [(smash_key,value)]
@return [void]

@overload smash_each(options = {})

@param options (see #smash)
@return [Enumerator<(smash_key,value)>]
# File lib/flatten.rb, line 53
def smash_each(options = {}, &block)
        Flatten.smash_each(self, options, &block)
end
smash_fetch(*args, &block) click to toggle source

Follows semantics of Hash#fetch

@overload smash_fetch(smash_key, options = {})

@param options (see #smash)
@raise [KeyError] if smash_key not foundĀ 
@return [Object]

@overload smash_fetch(smash_key, default, options = {})

@param options (see #smash)
@param default [Object] the default object
@return [default]

@overload smash_fetch(smash_key, options = {}, &block)

@param options (see #smash)
@yield if smash_key not founs
@return [Object] that which was returned by the given block.
# File lib/flatten.rb, line 71
def smash_fetch(*args, &block)
        Flatten.smash_fetch(self, *args, &block)
end
smash_get(*args) click to toggle source

Follows semantics of Hash#[] without support for Hash#default_proc

@overload smash_get(smash_key, options = {})

@param options (see #smash)
@return [Object] at that address or nil if none found
# File lib/flatten.rb, line 80
def smash_get(*args)
        Flatten.smash_get(self, *args)
end
unsmash(options = {}) click to toggle source

Returns a deeply-nested hash version of self.

@param options (see smash) @return [Hash<String,Object>]

# File lib/flatten.rb, line 88
def unsmash(options = {})
        Flatten.unsmash(self, options)
end
unsmash!(options = {}) click to toggle source

Replaces self with deeply-nested version of self.

@param options (see smash) @return [Hash<String,Object>]

# File lib/flatten.rb, line 96
def unsmash!(options = {})
        self.replace(unsmash, options)
end