Class: AWSCloudSearch::Document
- Inherits:
-
Object
- Object
- AWSCloudSearch::Document
- Defined in:
- lib/aws_cloud_search/document.rb
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#id ⇒ Object
Returns the value of attribute id.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
-
.type_attr_accessor(name, type) ⇒ Object
A typed attribute accessor helper.
Instance Method Summary collapse
-
#add_field(name, value) ⇒ Object
Adds a new field to the document.
-
#clear_fields ⇒ Object
Resets the fields.
-
#initialize(auto_version = false) ⇒ Document
constructor
Initializes the object.
-
#new_version ⇒ Object
Set a new version automatically.
-
#to_hash ⇒ Object
Return this object as a hash.
-
#to_json ⇒ Object
Return this object as json.
Constructor Details
#initialize(auto_version = false) ⇒ Document
Initializes the object
31 32 33 34 |
# File 'lib/aws_cloud_search/document.rb', line 31 def initialize(auto_version=false) @fields = {} new_version if auto_version end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
27 28 29 |
# File 'lib/aws_cloud_search/document.rb', line 27 def fields @fields end |
#id ⇒ Object
Returns the value of attribute id.
27 28 29 |
# File 'lib/aws_cloud_search/document.rb', line 27 def id @id end |
#type ⇒ Object
Returns the value of attribute type.
26 27 28 |
# File 'lib/aws_cloud_search/document.rb', line 26 def type @type end |
Class Method Details
.type_attr_accessor(name, type) ⇒ Object
A typed attribute accessor helper. When the value is set, if it does not match the pre-defined type, an exception is thrown.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/aws_cloud_search/document.rb', line 10 def self.type_attr_accessor(name, type) define_method(name) do instance_variable_get("@#{name}") end define_method("#{name}=") do |value| if value.is_a? type or value == nil instance_variable_set("@#{name}", value) else raise ArgumentError.new("Invalid Type") end end end |
Instance Method Details
#add_field(name, value) ⇒ Object
Adds a new field to the document
39 40 41 42 |
# File 'lib/aws_cloud_search/document.rb', line 39 def add_field(name, value) raise ArgumentError.new("Found invalid XML 1.0 unicode character(s)") if value.is_a? String and value =~ INVALID_CHAR_XML10 @fields[name] = value end |
#clear_fields ⇒ Object
Resets the fields.
52 53 54 |
# File 'lib/aws_cloud_search/document.rb', line 52 def clear_fields @fields = {} end |
#new_version ⇒ Object
Set a new version automatically
57 58 59 |
# File 'lib/aws_cloud_search/document.rb', line 57 def new_version @version = Time.now.to_i end |
#to_hash ⇒ Object
Return this object as a hash
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/aws_cloud_search/document.rb', line 62 def to_hash @fields.delete_if {|key,val| val.nil?} h = { :type => @type, :id => @id, :version => @version, :fields => @fields } h[:lang] = @lang unless (@type == 'delete') h end |
#to_json ⇒ Object
Return this object as json
76 77 78 |
# File 'lib/aws_cloud_search/document.rb', line 76 def to_json to_hash.to_json end |