Class: Setsumei::Describable::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/setsumei/describable/collection.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#klassObject

Returns the value of attribute klass.



11
12
13
# File 'lib/setsumei/describable/collection.rb', line 11

def klass
  @klass
end

#optionsObject

Returns the value of attribute options.



11
12
13
# File 'lib/setsumei/describable/collection.rb', line 11

def options
  @options
end

Class Method Details

.of(klass, options = {}) ⇒ Object



4
5
6
7
8
9
# File 'lib/setsumei/describable/collection.rb', line 4

def Collection.of(klass,options = {})
  new.tap do |collection|
    collection.klass = klass
    collection.options = options
  end
end

Instance Method Details

#set_value_on(object, options = {}) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/setsumei/describable/collection.rb', line 13

def set_value_on(object, options = {})
  return nil if options.empty? || options[:from_value_in].nil?

  array( extract_from_hash options[:from_value_in] ).each do |data|
    object << Build.a(klass, from: data)
  end
end