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
# File 'lib/cloud_search/document.rb', line 8

def initialize(attributes = {})
  attributes.each_pair { |key, value| self.__send__("#{key}=", value) }
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



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

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



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

def to_json
  JSON.unparse as_json
end

#valid?Boolean

Returns:

  • (Boolean)


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

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