Class: Tagliani::Search::Index::Object
- Inherits:
-
Object
- Object
- Tagliani::Search::Index::Object
- Defined in:
- lib/tagliani/search/index/object.rb
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(object = {}) ⇒ Object
constructor
A new instance of Object.
- #to_h ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(object = {}) ⇒ Object
Returns a new instance of Object.
5 6 7 |
# File 'lib/tagliani/search/index/object.rb', line 5 def initialize(object = {}) @object = object.is_a?(Hash) ? object.stringify_keys : JSON.parse(object) end |
Instance Method Details
#id ⇒ Object
9 10 11 |
# File 'lib/tagliani/search/index/object.rb', line 9 def id "#{@object['object_kls'].to_s.downcase}_#{@object['object_id']}_#{@object['tag_id']}" end |
#to_h ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/tagliani/search/index/object.rb', line 13 def to_h { object_kls: @object['object_kls'], object_id: @object['object_id'], object_created_at: @object['created_at'].try(:strftime, '%Y-%m-%d %H:%M:%S'), tag_id: @object['tag_id'], tag_kls: @object['tag_kls'], tag_type: @object['tag_type'], tag_name: @object['tag_name'], last_updated: @object['last_updated'].try(:strftime, '%Y-%m-%d %H:%M:%S') } end |
#to_json ⇒ Object
26 27 28 |
# File 'lib/tagliani/search/index/object.rb', line 26 def to_json to_h.to_json end |