Class: ContentsCore::ItemObject
- Inherits:
-
Item
show all
- Defined in:
- app/models/contents_core/item_object.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Item
#as_json, #attr_id, #class_name, #config, #data_type, #editable, #on_after_initialize, #on_before_create, #opt_input, #process_data, #set, types, #update_data, #validate_item
Class Method Details
.permitted_attributes ⇒ Object
34
35
36
|
# File 'app/models/contents_core/item_object.rb', line 34
def self.permitted_attributes
[ :data_hash ]
end
|
.type_name ⇒ Object
38
39
40
|
# File 'app/models/contents_core/item_object.rb', line 38
def self.type_name
'object'
end
|
Instance Method Details
#data ⇒ Object
6
7
8
|
# File 'app/models/contents_core/item_object.rb', line 6
def data
self.data_hash.deep_symbolize_keys
end
|
#data=(value) ⇒ Object
10
11
12
|
# File 'app/models/contents_core/item_object.rb', line 10
def data=( value )
self.data_hash = value
end
|
#from_string(value) ⇒ Object
19
20
21
22
23
24
25
26
27
28
|
# File 'app/models/contents_core/item_object.rb', line 19
def from_string( value )
if value.is_a? String
val = {}
value.each_line do |line|
m = line.match( /([^:]*):(.*)/ )
val[m[1]] = m[2].strip if m && !m[1].blank?
end
self.data_hash = val
end
end
|
#init ⇒ Object
14
15
16
17
|
# File 'app/models/contents_core/item_object.rb', line 14
def init
self.data = {} unless self.data
self
end
|
#to_s ⇒ Object
30
31
32
|
# File 'app/models/contents_core/item_object.rb', line 30
def to_s
self.data_hash ? self.data_hash.inject( '' ) { |k, v| "#{k}#{v[0]}: #{v[1]}\n" } : {}
end
|