Class: MongoSphinx::Indexer::XMLDoc
- Inherits:
-
Object
- Object
- MongoSphinx::Indexer::XMLDoc
- Defined in:
- lib/indexer.rb
Overview
Class XMLDoc wraps the XML representation of a single document to index and contains a complete “sphinx:document” tag.
Instance Attribute Summary collapse
-
#class_name ⇒ Object
readonly
Returns the class name of the encoded data.
-
#id ⇒ Object
readonly
Returns the ID of the encoded data.
-
#xml ⇒ Object
readonly
Returns the encoded data.
Class Method Summary collapse
-
.from_object(object) ⇒ Object
Creates a XMLDoc object from the provided CouchRest object.
Instance Method Summary collapse
-
#initialize(id, class_name, properties) ⇒ XMLDoc
constructor
Creates a XMLDoc object from the provided ID, class name and data.
-
#to_s ⇒ Object
Returns the encoded data as XML.
-
#to_xml ⇒ Object
Returns the encoded data as XML.
Constructor Details
#initialize(id, class_name, properties) ⇒ XMLDoc
Creates a XMLDoc object from the provided ID, class name and data.
Parameters:
- id
-
ID of the object to index
- class_name
-
Name of the class
- data
-
Hash with the properties to index
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/indexer.rb', line 181 def initialize(id, class_name, properties) raise ArgumentError, 'Missing id' if id.nil? raise ArgumentError, 'Missing class_name' if class_name.nil? xml = "<sphinx:document id=\"#{id}\">" xml << '<csphinx-class>' xml << MongoSphinx::MultiAttribute.encode(class_name) xml << '</csphinx-class>' xml << "<classname>#{class_name}</classname>" properties.each do |key, value| xml << "<#{key}><![CDATA[[#{value}]]></#{key}>" end xml << '</sphinx:document>' @xml = xml @id = id @class_name = class_name end |
Instance Attribute Details
#class_name ⇒ Object (readonly)
Returns the class name of the encoded data.
154 155 156 |
# File 'lib/indexer.rb', line 154 def class_name @class_name end |
#id ⇒ Object (readonly)
Returns the ID of the encoded data.
150 151 152 |
# File 'lib/indexer.rb', line 150 def id @id end |
#xml ⇒ Object (readonly)
Returns the encoded data.
158 159 160 |
# File 'lib/indexer.rb', line 158 def xml @xml end |
Class Method Details
.from_object(object) ⇒ Object
Creates a XMLDoc object from the provided CouchRest object.
Parameters:
- object
-
Object to index
166 167 168 169 170 171 |
# File 'lib/indexer.rb', line 166 def self.from_object(object) raise ArgumentError, 'Missing object' if object.nil? raise ArgumentError, 'No compatible ID' if (id = object.sphinx_id).nil? return new(id, object.class.to_s, object.fulltext_attributes) end |
Instance Method Details
#to_s ⇒ Object
Returns the encoded data as XML.
212 213 214 |
# File 'lib/indexer.rb', line 212 def to_s return self.xml end |
#to_xml ⇒ Object
Returns the encoded data as XML.
206 207 208 |
# File 'lib/indexer.rb', line 206 def to_xml return to_s end |