Class: CloudSearch::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud_search/document.rb

Constant Summary collapse

MAX_VERSION =
4294967295

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Document

Returns a new instance of Document.



8
9
10
11
# File 'lib/cloud_search/document.rb', line 8

def initialize(attributes = {})
  attributes.each_pair { |key, value| self.__send__("#{key}=", value) }
  @errors = {}
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



6
7
8
# File 'lib/cloud_search/document.rb', line 6

def errors
  @errors
end

#fieldsObject

Returns the value of attribute fields.



5
6
7
# File 'lib/cloud_search/document.rb', line 5

def fields
  @fields
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/cloud_search/document.rb', line 6

def id
  @id
end

#langObject

Returns the value of attribute lang.



5
6
7
# File 'lib/cloud_search/document.rb', line 5

def lang
  @lang
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/cloud_search/document.rb', line 5

def type
  @type
end

#versionObject

Returns the value of attribute version.



6
7
8
# File 'lib/cloud_search/document.rb', line 6

def version
  @version
end

Instance Method Details

#as_jsonObject



35
36
37
38
39
# File 'lib/cloud_search/document.rb', line 35

def as_json
  {:type => type, :id => id, :version => version}.tap do |hash|
    hash.merge!(:lang => lang, :fields => fields) if type == "add"
  end
end

#to_jsonObject



41
42
43
# File 'lib/cloud_search/document.rb', line 41

def to_json
  JSON.unparse as_json
end

#valid?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
# File 'lib/cloud_search/document.rb', line 25

def valid?
  @errors = {}
  run_id_validations
  run_version_validations
  run_type_validations
  run_lang_validations
  run_fields_validations
  errors.empty?
end