Sha256: dba6f51a4827ccff4ea1f469f62ef087b5f1407d6e5ad8b59a4cad5dec63c676
Contents?: true
Size: 1.01 KB
Versions: 10
Compression:
Stored size: 1.01 KB
Contents
# # collection.rb # Crowdskout # # Copyright (c) 2016 Kyle Schutt. All rights reserved. module Crowdskout module Components class Collection < Component attr_accessor :key_name, :items # Factory method to create an Collection object from a json string # @param [String] key_name - name of the collection # @param [Array] items - properties to create object from # @return [Collection] def self.create(props) obj = Collection.new obj.items = [] props.each do |key, value| obj.key_name = key if value.is_a?(Hash) || value.is_a?(Array) value.each do |collection| obj.items << Components::Item.create(collection) end else obj.items << Components::Item.create({ key => value }) end end obj end # Hash override to generate the correct hash def to_hash { key_name => items.collect(&:to_hash) } end end end end
Version data entries
10 entries across 10 versions & 1 rubygems