Class: Elasticated::Document
- Inherits:
-
Object
- Object
- Elasticated::Document
- Includes:
- BlockEvaluation
- Defined in:
- lib/elasticated/document.rb
Instance Attribute Summary collapse
-
#document_source ⇒ Object
Returns the value of attribute document_source.
-
#id ⇒ Object
Returns the value of attribute id.
-
#index ⇒ Object
Returns the value of attribute index.
-
#score ⇒ Object
Returns the value of attribute score.
-
#type ⇒ Object
Returns the value of attribute type.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(source = nil) ⇒ Document
constructor
A new instance of Document.
- #source ⇒ Object
- #source=(hash) ⇒ Object
Methods included from BlockEvaluation
Constructor Details
#initialize(source = nil) ⇒ Document
33 34 35 |
# File 'lib/elasticated/document.rb', line 33 def initialize(source=nil) self.source = source if source end |
Instance Attribute Details
#document_source ⇒ Object
Returns the value of attribute document_source.
31 32 33 |
# File 'lib/elasticated/document.rb', line 31 def document_source @document_source end |
#id ⇒ Object
Returns the value of attribute id.
31 32 33 |
# File 'lib/elasticated/document.rb', line 31 def id @id end |
#index ⇒ Object
Returns the value of attribute index.
31 32 33 |
# File 'lib/elasticated/document.rb', line 31 def index @index end |
#score ⇒ Object
Returns the value of attribute score.
31 32 33 |
# File 'lib/elasticated/document.rb', line 31 def score @score end |
#type ⇒ Object
Returns the value of attribute type.
31 32 33 |
# File 'lib/elasticated/document.rb', line 31 def type @type end |
#version ⇒ Object
Returns the value of attribute version.
31 32 33 |
# File 'lib/elasticated/document.rb', line 31 def version @version end |
Class Method Details
.create(opts = {}, &block) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/elasticated/document.rb', line 6 def create(opts={}, &block) raise if block && !opts.empty? ret = new if opts.empty? ret.evaluate block else opts.each{ |k, v| ret.send "#{k}=", v if v } end ret end |
.from_elasticsearch_hit(hit) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/elasticated/document.rb', line 17 def from_elasticsearch_hit(hit) document = new hit['_source'] document.id = hit['_id'] document.type = hit['_type'] document.index = hit['_index'] document.score = hit['_score'] document.version = hit['_version'] document end |
Instance Method Details
#source ⇒ Object
41 42 43 |
# File 'lib/elasticated/document.rb', line 41 def source self.document_source ||= Hash::Accessible.new end |
#source=(hash) ⇒ Object
37 38 39 |
# File 'lib/elasticated/document.rb', line 37 def source=(hash) self.document_source = Hash::Accessible.new hash end |