Sha256: 845710d41b3f80eff2190a7bffb3dfde508294e99b720deff391d2d8df450234

Contents?: true

Size: 1.22 KB

Versions: 25

Compression:

Stored size: 1.22 KB

Contents

module Endeca
  module Transformer
    # Requires existence of mappings accessor (Hash)
    #
    # ==== Examples
    #   # Standard map call that returns an Endeca::Map object
    #   map(:old_name => :new_name)
    #
    #   # Allows to to create a map object to perform other functionality such
    #   # as transformations.
    #   map(:new_name)
    def map(mapping = {})
      mapping = {mapping => mapping} if Symbol === mapping
      mapping = mapping.symbolize_keys

      if mapping.length > 1
        raise ArgumentError, "map only accepts one key=>value pair" 
      end

      mapping.each do |key, transformed_key|
        transformed_key = key unless transformed_key
        return mappings[key] = Map.new(key, transformed_key)
      end
    end

    # Use the mappings hash to replace domain level query query_options with
    # their Endeca equivalent.
    def transform_query_options(query_options)
      # {"apartments" => true}
      query = query_options.symbolize_keys
      # {:apartments => true}
      query.each do |key, _|
        if mapping = mappings[key]
          new_options = mapping.perform(query)
          query.delete(key)
          query.update(new_options)
        end
      end
      query
    end
 
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
primedia-endeca-0.10.0 lib/endeca/transformer.rb
primedia-endeca-0.10.1 lib/endeca/transformer.rb
primedia-endeca-0.11.0 lib/endeca/transformer.rb
primedia-endeca-0.12.0 lib/endeca/transformer.rb
primedia-endeca-0.14.0 lib/endeca/transformer.rb
primedia-endeca-0.9.20 lib/endeca/transformer.rb
primedia-endeca-0.9.21 lib/endeca/transformer.rb
primedia-endeca-0.9.22 lib/endeca/transformer.rb
primedia-endeca-0.9.23 lib/endeca/transformer.rb
primedia-endeca-0.9.24 lib/endeca/transformer.rb
primedia-endeca-0.9.25 lib/endeca/transformer.rb
primedia-endeca-0.9.26 lib/endeca/transformer.rb
primedia-endeca-1.0.0 lib/endeca/transformer.rb
primedia-endeca-1.1.0 lib/endeca/transformer.rb
primedia-endeca-1.2.0 lib/endeca/transformer.rb
primedia-endeca-1.3.0 lib/endeca/transformer.rb
primedia-endeca-1.3.1 lib/endeca/transformer.rb
primedia-endeca-1.3.2 lib/endeca/transformer.rb
primedia-endeca-1.3.3 lib/endeca/transformer.rb
primedia-endeca-1.3.4 lib/endeca/transformer.rb