Class: MetaBuilder::ParameterTypes::HTMLColorParameter

Inherits:
MetaBuilder::ParameterType show all
Defined in:
lib/MetaBuilder/Parameters/styles.rb

Overview

A HTML color: the value is returned in the form of an array of three integers between 0 and 255. Strings can be in the form of a standard HTML color like #FF0000 for red, or it can be a name corresponding to a constant in one of the modules given in the :namespaces array.

Instance Method Summary collapse

Methods inherited from MetaBuilder::ParameterType

#default_value, from_string, get_param_type, get_type, #initialize, #lookup_const, #option_parser_long_option, #option_parser_option, #option_parser_raw, #qt4_create_input_widget, #qt4_get, #string_to_type, #stt_run_hook, #type_name, type_name, #type_to_string, #type_to_variant, #variant_to_type

Constructor Details

This class inherits a constructor from MetaBuilder::ParameterType

Instance Method Details

#string_to_type_internal(str) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/MetaBuilder/Parameters/styles.rb', line 35

def string_to_type_internal(str)
  if str =~ /#([0-9a-fA-F]{6})/
    return $1.scan(/../).map {|i| i.to_i(16)}
  elsif @type.has_key?(:namespaces) 
    for mod in @type[:namespaces]
      if mod.const_defined?(str)
        return normalize(mod.const_get(str))
      end
    end
  else
    raise IncorrectInput, "#{str} is not a valid color"
  end
end

#type_to_string_internal(color) ⇒ Object



49
50
51
# File 'lib/MetaBuilder/Parameters/styles.rb', line 49

def type_to_string_internal(color)
  return "##{color.map {|i| sprintf("%02x",i)}.join}"
end