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
- .create(opts = {}, &block) ⇒ Object
- .parse(hit) ⇒ Object (also: from_elasticsearch_hit)
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
Returns a new instance of Document.
34 35 36 |
# File 'lib/elasticated/document.rb', line 34 def initialize(source=nil) self.source = source if source end |
Instance Attribute Details
#document_source ⇒ Object
Returns the value of attribute document_source.
32 33 34 |
# File 'lib/elasticated/document.rb', line 32 def document_source @document_source end |
#id ⇒ Object
Returns the value of attribute id.
32 33 34 |
# File 'lib/elasticated/document.rb', line 32 def id @id end |
#index ⇒ Object
Returns the value of attribute index.
32 33 34 |
# File 'lib/elasticated/document.rb', line 32 def index @index end |
#score ⇒ Object
Returns the value of attribute score.
32 33 34 |
# File 'lib/elasticated/document.rb', line 32 def score @score end |
#type ⇒ Object
Returns the value of attribute type.
32 33 34 |
# File 'lib/elasticated/document.rb', line 32 def type @type end |
#version ⇒ Object
Returns the value of attribute version.
32 33 34 |
# File 'lib/elasticated/document.rb', line 32 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 |
.parse(hit) ⇒ Object Also known as: from_elasticsearch_hit
17 18 19 20 21 22 23 24 25 |
# File 'lib/elasticated/document.rb', line 17 def parse(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
42 43 44 |
# File 'lib/elasticated/document.rb', line 42 def source self.document_source ||= Hash::Accessible.new end |
#source=(hash) ⇒ Object
38 39 40 |
# File 'lib/elasticated/document.rb', line 38 def source=(hash) self.document_source = Hash::Accessible.new hash end |