Class: Neuromancer::Indexer::Document
- Inherits:
-
Object
- Object
- Neuromancer::Indexer::Document
- Defined in:
- lib/neuromancer/indexer/document.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #as_json ⇒ Object
- #indifferent_value(hash, key) ⇒ Object
-
#initialize(attributes) ⇒ Document
constructor
A new instance of Document.
- #validate! ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Document
Returns a new instance of Document.
8 9 10 11 12 |
# File 'lib/neuromancer/indexer/document.rb', line 8 def initialize(attributes) @id = indifferent_value(attributes, :id).to_s @type = indifferent_value(attributes, :type).to_s @attributes = indifferent_value(attributes, :attributes) end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
6 7 8 |
# File 'lib/neuromancer/indexer/document.rb', line 6 def attributes @attributes end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/neuromancer/indexer/document.rb', line 6 def id @id end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/neuromancer/indexer/document.rb', line 6 def type @type end |
Instance Method Details
#as_json ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/neuromancer/indexer/document.rb', line 14 def as_json { id: id, type: type, attributes: attributes } end |
#indifferent_value(hash, key) ⇒ Object
32 33 34 |
# File 'lib/neuromancer/indexer/document.rb', line 32 def indifferent_value(hash, key) hash[key.to_sym] || hash[key.to_s] end |
#validate! ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/neuromancer/indexer/document.rb', line 22 def validate! errors = [] errors << 'document#id is empty' if id.empty? errors << 'document#type is empty' if type.empty? errors << 'document#attributes is not a Hash' unless attributes.is_a?(Hash) raise(InvalidDocument, errors) unless errors.empty? end |