Sha256: c58116866943560a6ed5581a01a2cf0f7baed94371ccd3f89d322cce221a6d11

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

module NetLinx
  module ERB
    
    # A collection of helper methods for use in Hash
    module HashHelpers
      
      # Template suffix (capitalized / unmodified).
      def tmpl_suffix
        Hash.instance_variable_get :@tmpl_suffix
      end
      
      # Template suffix for variables (lowercase).
      def tmpl_var_suffix
        Hash.instance_variable_get :@tmpl_var_suffix
      end
      
      # Append the @tmpl_suffix to each key in the hash.
      def append_suffix
        hash = self.map do |k,v|
          key_name = "#{k}"
          key_name += "_#{tmpl_suffix}" if tmpl_suffix and not tmpl_suffix.empty?
          
          [key_name.to_sym, v]
        end
        
        Hash[hash]
      end
      
      # Append the @tmpl_suffix to each key in the hash and overwrite this
      # hash with the result.
      def append_suffix!
        hash = append_suffix
        self.clear
        self.merge! hash
      end
      
    end
  end
end

Hash.class_eval { include NetLinx::ERB::HashHelpers }

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
netlinx-erb-2.0.1 lib/netlinx/erb/hash_helpers.rb
netlinx-erb-2.0.0 lib/netlinx/erb/hash_helpers.rb
netlinx-erb-1.1.0 lib/netlinx/erb/hash_helpers.rb
netlinx-erb-1.0.0 lib/netlinx/erb/hash_helpers.rb