class Interview::Control

Attributes

parent[RW]

Public Class Methods

new(params={}) click to toggle source
# File lib/interview/control.rb, line 7
def initialize(params={})
  set_attributes(params)
  set_defaults
end

Public Instance Methods

ancestors() click to toggle source
# File lib/interview/control.rb, line 29
def ancestors
  if @parent.nil?
    return []
  else
    return [@parent] + @parent.ancestors
  end
end
build(b) { || ... } click to toggle source
# File lib/interview/control.rb, line 61
def build(b)
  yield if block_given?
end
build_child(b, control, &block) click to toggle source
# File lib/interview/control.rb, line 70
def build_child(b, control, &block)
  b.add! control, &block
end
build_with_params(b, params={}) click to toggle source
# File lib/interview/control.rb, line 65
def build_with_params(b, params={})
  set_attributes(params)
  build(b)
end
find_attribute(attribute) click to toggle source
# File lib/interview/control.rb, line 37
def find_attribute(attribute)
  if respond_to? attribute
    value = send attribute
    return value if value
  end
  if @parent
    return @parent.find_attribute(attribute)
  else
    return nil
  end
  # return nil if @parent.nil?
  # if @parent.respond_to? attribute
    # return @parent.send attribute
  # else
    # return @parent.find_attribute attribute
  # end
end
find_attribute!(attr_name) click to toggle source
# File lib/interview/control.rb, line 55
def find_attribute!(attr_name)
  attribute = find_attribute(attr_name)
  throw "Attribute #{attr_name} was not found." if attribute.nil?
  return attribute
end
set_attributes(params={}) click to toggle source
# File lib/interview/control.rb, line 12
def set_attributes(params={})
  params.each do |key, value|
    key = "#{key}=".to_sym
    if respond_to?(key) # and not value.nil?
      send(key, value)
    end
  end
end
set_defaults() click to toggle source
# File lib/interview/control.rb, line 21
def set_defaults # todo: löschen?
  if self.class.const_defined? 'DEFAULTS'
    self.class::DEFAULTS.each do |key, value|
      self.send("#{key}=".to_sym, value)
    end
  end
end