Class: Brandmaker::GridVariable

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

Instance Attribute Summary

Attributes inherited from Variable

#config

Instance Method Summary collapse

Methods inherited from Variable

#data, #initialize, #label, #purpose, #technical_name, #type_id

Constructor Details

This class inherits a constructor from Brandmaker::Variable

Instance Method Details

#actual_valuesObject



25
26
27
28
29
# File 'lib/brandmaker/grid_variable.rb', line 25

def actual_values
  rows.map do |row|
    row.try(:[], :variable).try(:[], :value).presence
  end.compact
end

#custom_structureObject



50
51
52
53
# File 'lib/brandmaker/grid_variable.rb', line 50

def custom_structure
  @custom_structure ||= Brandmaker::CustomStructure.find_by_technical_name(self.technical_name)
  @custom_structure
end

#custom_structure_valuesObject



31
32
33
34
35
36
37
38
# File 'lib/brandmaker/grid_variable.rb', line 31

def custom_structure_values
  actual_values.collect do |val|
    obj = custom_structure.objects.find do |object|
      object[:name] == val
    end
    obj[:label]
  end
end

#extract_email(val) ⇒ Object



46
47
48
# File 'lib/brandmaker/grid_variable.rb', line 46

def extract_email val
  val.match(/\(([^)]+)\)/).try(:[], 1)
end

#rowsObject



40
41
42
43
44
# File 'lib/brandmaker/grid_variable.rb', line 40

def rows
  values = @data[:grid][:row]
  values = [values] if values.is_a? Hash
  values
end

#valueObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/brandmaker/grid_variable.rb', line 7

def value
  begin
    if custom_structure.present?
      values = custom_structure_values
    else
      values = actual_values
    end

    if purpose == VariablePurpose::EMAIL_RECIPIENT
      values.map { |val| extract_email val }.compact
    else
      values
    end
  rescue
    super
  end
end