module Iup::AttributeBuilders

methods to help construct attribute methods

Public Instance Methods

define_attribute(name) click to toggle source

Given the name of an attribute, this method creates a new method which accepts an optional value. Providing the value will set the named attribute for this object, or else its current value will be returned.

# File lib/wrapped/attribute-builders.rb, line 11
def define_attribute name
  attribute = name.to_s.upcase
  define_method name do |val=nil|
    if val.nil?
      IupLib.IupGetAttribute(@handle, attribute).first
    else
      IupLib.IupSetAttribute @handle, attribute, val.to_s
    end
  end
end
define_id_attribute(name) click to toggle source

Given the name of an attribute, this method creates a new method requiring an id number as a parameter and an optional value. Providing the value will set the named attribute for this object using the id number, e.g. “ITEM1”, or else the current value will be returned. This supports attributes such as “ITEM1” “ITEM2” by making the id number a parameter.

# File lib/wrapped/attribute-builders.rb, line 46
def define_id_attribute name
  define_method name do |id, val=nil|
    attribute = "#{name}#{id}".upcase
    if val.nil?
      IupLib.IupGetAttribute(@handle, attribute).first
    else
      IupLib.IupSetAttribute @handle, attribute, val.to_s
    end
  end
end
define_id_readonly(name) click to toggle source

Given the name of an attribute, this method creates a new method requiring an id number as a parameter. The current value of the attribute name + id will be returned. This supports attributes such as “ITEM1” “ITEM2” by making the id number a parameter.

# File lib/wrapped/attribute-builders.rb, line 61
def define_id_readonly name
  define_method name do |id|
    IupLib.IupGetAttribute(@handle, "#{name}#{id}".upcase).first
  end
end
define_id_writeonly(name) click to toggle source

Given the name of an attribute, this method creates a new method requiring an id number as a parameter and a value. Providing the value will set the named attribute for this object using the id number, e.g. “ITEM1”. This supports attributes such as “ITEM1” “ITEM2” by making the id number a parameter.

# File lib/wrapped/attribute-builders.rb, line 72
def define_id_writeonly name
  define_method name do |id, val|
    IupLib.IupSetAttribute @handle, "#{name}#{id}".upcase, val.to_s
  end
end
define_property_attribute(name) click to toggle source

Given the name of an attribute, this method creates a new method taking a property name and an optional value. If given the value, the new method will set the attribute's property to the value. Otherwise, the current value of the attribute's property will be returned. This supports attributes such as “ITEM=val”, providing a parameter for the property name.

# File lib/wrapped/attribute-builders.rb, line 83
def define_property_attribute name
  attribute = name.to_s.upcase
  define_method name do |property, val=nil|
    if val.nil?
      IupLib.IupGetAttribute(@handle, attribute, property.upcase).first
    else
      IupLib.IupSetAttribute @handle, attribute, "#{property}=#{val}".upcase
    end
  end
end
define_property_writeonly(name) click to toggle source

Given the name of an attribute, this method creates a new method taking a property name and a value. The new method will set the attribute's property to the value. This supports attributes such as “ITEM=val”, providing a parameter for the property name.

# File lib/wrapped/attribute-builders.rb, line 98
def define_property_writeonly name
  attribute = name.to_s.upcase
  define_method name do |property, val|
    IupLib.IupSetAttribute @handle, attribute, "#{property}=#{val}".upcase
  end
end
define_readonly(name) click to toggle source

Given the name of an attribute, this method creates a new method which returns its current value.

# File lib/wrapped/attribute-builders.rb, line 24
def define_readonly name
  attribute = name.to_s.upcase
  define_method name do
    IupLib.IupGetAttribute(@handle, attribute).first
  end
end
define_writeonly(name) click to toggle source

Given the name of an attribute, this method creates a new method which accepts a value and sets the named attribute for this object.

# File lib/wrapped/attribute-builders.rb, line 34
def define_writeonly name
  attribute = name.to_s.upcase
  define_method name do |val|
    IupLib.IupSetAttribute @handle, attribute, val
  end
end