Class: Brandmaker::VariableCollection

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

Instance Method Summary collapse

Constructor Details

#initialize(variables, create = true) ⇒ VariableCollection

Returns a new instance of VariableCollection.



4
5
6
7
8
9
10
# File 'lib/brandmaker/variable_collection.rb', line 4

def initialize variables, create = true
  if create
    super variables.map { |var| Brandmaker::Variable.new(var) }
  else
    super variables
  end
end

Instance Method Details

#find_by_purpose(purpose) ⇒ Object



16
17
18
19
20
# File 'lib/brandmaker/variable_collection.rb', line 16

def find_by_purpose(purpose)
  find do |variable|
    variable.purpose == purpose 
  end || raise("#{purpose} is not configured for this job")
end

#find_by_technical_name(technical_name) ⇒ Object



12
13
14
# File 'lib/brandmaker/variable_collection.rb', line 12

def find_by_technical_name(technical_name)
  find { |variable| variable.technical_name == technical_name }
end

#unpurposedObject



22
23
24
# File 'lib/brandmaker/variable_collection.rb', line 22

def unpurposed
  VariableCollection.new self.select { |var| var.purpose.blank? }, false
end