Sha256: eb76f408646bf82859c72ad0d52613101363d702833a3ddf128b833b81504581

Contents?: true

Size: 702 Bytes

Versions: 4

Compression:

Stored size: 702 Bytes

Contents

# TODO: needs improvements
module ContentsCore
  class ItemObject < Item
    alias_attribute :data, :data_hash

    serialize :data_hash, JSON

    def init
      self.data = {}
      self
    end

    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

    def to_s
      self.data_hash ? self.data_hash.inject( '' ) { |k, v| k + v[0] + ': ' + v[1] + "\n" } : {}
    end

    def self.permitted_attributes
      [ :data_hash ]
    end

    def self.type_name
      'object'
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
contents_core-0.2.5 app/models/contents_core/item_object.rb
contents_core-0.2.4 app/models/contents_core/item_object.rb
contents_core-0.2.2 app/models/contents_core/item_object.rb
contents_core-0.2.0 app/models/contents_core/item_object.rb