Class: Endeca::Map
Instance Method Summary collapse
-
#==(other) ⇒ Object
Mapping object is equal to other mapping object if their attributes are equal.
-
#boolean ⇒ Object
Convert true and false into their Endeca equivalents.
- #boolean? ⇒ Boolean
-
#enclose(str) ⇒ Object
When mapping multiple values, enclose the values in the string provided to
enclose
. - #enclose? ⇒ Boolean
- #having(hash) ⇒ Object
- #having? ⇒ Boolean
-
#initialize(old_key, new_key = nil) ⇒ Map
constructor
A new instance of Map.
- #inspect ⇒ Object
-
#into(hash) ⇒ Object
Mapping actually resides in another key, value pair.
- #into? ⇒ Boolean
-
#join(character) ⇒ Object
When mapping multiple key/value pairs to one or two parameter values (via
into
), use this character to join each pair. - #join? ⇒ Boolean
-
#perform(current_query) ⇒ Object
Perform the mapping as defined for the current_query.
-
#replace! ⇒ Object
When mapping multiple key/value pairs, replace existing keys with the new keys rather than joining.
- #replace? ⇒ Boolean
-
#split_into(hash, split_value = ',') ⇒ Object
Mapping actually resides in another key, value pair.
-
#transform(&block) ⇒ Object
Code block to execute on the original data.
-
#with(character) ⇒ Object
When mapping multiple key/value pairs to a single parameter value (via
into
), use this character to join a key with a value.
Constructor Details
#initialize(old_key, new_key = nil) ⇒ Map
Returns a new instance of Map.
3 4 5 6 7 |
# File 'lib/endeca/map.rb', line 3 def initialize(old_key, new_key=nil) @old_key = old_key @new_key = new_key || @old_key boolean end |
Instance Method Details
#==(other) ⇒ Object
Mapping object is equal to other mapping object if their attributes are equal
124 125 126 |
# File 'lib/endeca/map.rb', line 124 def ==(other) equality_elements == other.equality_elements end |
#boolean ⇒ Object
Convert true and false into their Endeca equivalents
10 11 12 13 14 15 |
# File 'lib/endeca/map.rb', line 10 def boolean @boolean = true add_transformation { |value| value == true ? 1 : value } add_transformation { |value| value == false ? 0 : value } self end |
#boolean? ⇒ Boolean
17 |
# File 'lib/endeca/map.rb', line 17 def boolean?; @boolean end |
#enclose(str) ⇒ Object
When mapping multiple values, enclose the values in the string provided to enclose
.
92 93 94 95 |
# File 'lib/endeca/map.rb', line 92 def enclose(str) @enclose = str self end |
#enclose? ⇒ Boolean
97 |
# File 'lib/endeca/map.rb', line 97 def enclose?; @enclose end |
#having(hash) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/endeca/map.rb', line 42 def having(hash) hash = hash.intern if hash.respond_to?(:intern) if hash.is_a?(Hash) raise ArgumentError, "Only one key/value pair allowed" if hash.size > 1 hash = hash.to_a.flatten hash = {hash.first.to_sym => hash.last.to_sym} end @having = hash self end |
#having? ⇒ Boolean
53 |
# File 'lib/endeca/map.rb', line 53 def having?; @having end |
#inspect ⇒ Object
128 129 130 |
# File 'lib/endeca/map.rb', line 128 def inspect perform({ @old_key => "" }).inspect end |
#into(hash) ⇒ Object
Mapping actually resides in another key, value pair. Uses Endeca default join characters (can be overridden by specifying with
and/or join
).
Example:
map(:city => :propertycity).into(:ntk => :ntt)
Document.all(:city => 'Atlanta') =>
?ntk=propercity&ntt=>Atlanta
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/endeca/map.rb', line 27 def into(hash) hash = hash.intern if hash.respond_to?(:intern) if hash.is_a?(Hash) raise ArgumentError, "Only one key/value pair allowed" if hash.size > 1 hash = hash.to_a.flatten hash = {hash.first.to_sym => hash.last.to_sym} end @into = hash with ':' join '|' self end |
#into? ⇒ Boolean
40 |
# File 'lib/endeca/map.rb', line 40 def into?; @into end |
#join(character) ⇒ Object
When mapping multiple key/value pairs to one or two parameter values (via into
), use this character to join each pair.
77 78 79 80 |
# File 'lib/endeca/map.rb', line 77 def join(character) @join = character self end |
#join? ⇒ Boolean
82 |
# File 'lib/endeca/map.rb', line 82 def join?; @join end |
#perform(current_query) ⇒ Object
Perform the mapping as defined for the current_query
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/endeca/map.rb', line 109 def perform(current_query) @current_query = current_query.symbolize_keys @current_value = @current_query[@old_key] perform_transformation perform_map perform_into perform_having perform_join return @new_query end |
#replace! ⇒ Object
When mapping multiple key/value pairs, replace existing keys with the new keys rather than joining.
101 102 103 104 |
# File 'lib/endeca/map.rb', line 101 def replace! @replace = true self end |
#replace? ⇒ Boolean
106 |
# File 'lib/endeca/map.rb', line 106 def replace?; @replace end |
#split_into(hash, split_value = ',') ⇒ Object
Mapping actually resides in another key, value pair. Uses Endeca default join characters (can be overridden by specifying with
and/or join
).
Example:
map(:city => :propertycity).split_into(:ntk => :ntt)
Document.all(:city => 'Atlanta, New York, Los Angeles') =>
?ntk=propercity|propertycity|propertycity&ntt=>Atlanta|New York|Los Angeles
63 64 65 66 |
# File 'lib/endeca/map.rb', line 63 def split_into(hash, split_value = ',') into(hash) @split_value = split_value end |
#transform(&block) ⇒ Object
Code block to execute on the original data
85 86 87 88 |
# File 'lib/endeca/map.rb', line 85 def transform(&block) add_transformation block self end |
#with(character) ⇒ Object
When mapping multiple key/value pairs to a single parameter value (via into
), use this character to join a key with a value.
70 71 72 73 |
# File 'lib/endeca/map.rb', line 70 def with(character) @with = character self end |