Class: Brandmaker::VariableConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/brandmaker/variable_config.rb

Constant Summary collapse

VARIABLE_TYPES =
{
  :""             => Variable,
  :media          => MediaVariable,
  :external_media => ExternalMediaVariable,
  :grid           => GridVariable
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*h) ⇒ VariableConfig

Returns a new instance of VariableConfig.



20
21
22
23
24
# File 'lib/brandmaker/variable_config.rb', line 20

def initialize(*h)
  if h.length == 1 && h.first.kind_of?(Hash)
    h.first.each { |k,v| send("#{k}=",v) }
  end
end

Instance Attribute Details

#content_typeObject

Returns the value of attribute content_type.



10
11
12
# File 'lib/brandmaker/variable_config.rb', line 10

def content_type
  @content_type
end

#labelObject

Returns the value of attribute label.



9
10
11
# File 'lib/brandmaker/variable_config.rb', line 9

def label
  @label
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/brandmaker/variable_config.rb', line 7

def name
  @name
end

#purposeObject

Returns the value of attribute purpose.



11
12
13
# File 'lib/brandmaker/variable_config.rb', line 11

def purpose
  @purpose
end

Instance Method Details

#to_typed_instance(data) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/brandmaker/variable_config.rb', line 26

def to_typed_instance(data)
  type = content_type
  klass = VARIABLE_TYPES[content_type.to_s.downcase.to_sym]
  unless klass.nil?
    instance = klass.new(data)
    instance.config = self
    instance
  else
    raise "Unknown variable type #{type}"
  end
end