Class: Esse::HashDocument

Inherits:
Document
  • Object
show all
Defined in:
lib/esse/hash_document.rb

Constant Summary collapse

META_KEYS =
%i[_id _type _routing routing].freeze

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ HashDocument



7
8
9
10
# File 'lib/esse/hash_document.rb', line 7

def initialize(object)
  @object = object
  @options = {}
end

Instance Method Details

#idString, Number



13
14
15
# File 'lib/esse/hash_document.rb', line 13

def id
  object['_id'] || object[:_id] || object['id'] || object[:id]
end

#metaHash



28
29
30
# File 'lib/esse/hash_document.rb', line 28

def meta
  {}
end

#routingString?



23
24
25
# File 'lib/esse/hash_document.rb', line 23

def routing
  object['_routing'] || object[:_routing] || object['routing'] || object[:routing]
end

#sourceHash

This method is abstract.

Override this method to return the document source

Returns the document source.



34
35
36
# File 'lib/esse/hash_document.rb', line 34

def source
  object.reject { |key, _| META_KEYS.include?(key.to_sym) }
end

#typeString?



18
19
20
# File 'lib/esse/hash_document.rb', line 18

def type
  object['_type'] || object[:_type]
end