Class: CTioga2::MetaBuilder::Types::TiogaColorType
- Inherits:
-
CTioga2::MetaBuilder::Type
- Object
- CTioga2::MetaBuilder::Type
- CTioga2::MetaBuilder::Types::TiogaColorType
- Defined in:
- lib/ctioga2/metabuilder/types/styles.rb
Overview
A color for use with Tioga, ie a [red, green, blue] array of values between 0 and 1.0. It accepts HTML-like colors, or three comma-separated values between 0 and 1.
Constant Summary collapse
- HLSRegexp =
/(?:hls):/i
Instance Attribute Summary
Attributes inherited from CTioga2::MetaBuilder::Type
#passthrough, #re_shortcuts, #shortcuts, #type
Instance Method Summary collapse
Methods inherited from CTioga2::MetaBuilder::Type
#boolean?, #default_value, from_string, get_param_type, get_type, #initialize, #option_parser_long_option, #option_parser_option, #string_to_type, #type_name, type_name, #type_to_string
Constructor Details
This class inherits a constructor from CTioga2::MetaBuilder::Type
Instance Method Details
#string_to_type_internal(str) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ctioga2/metabuilder/types/styles.rb', line 37 def string_to_type_internal(str) if str =~ HLSRegexp hls = true str = str.gsub(HLSRegexp,'') else hls = false end if str =~ /^\s*#([0-9a-fA-F]{6})\s*$/ value = $1.scan(/../).map { |i| i.to_i(16)/255.0 } elsif str =~ /^\s*#([0-9a-fA-F]{3})\s*$/ value = $1.scan(/./).map { |i| i.to_i(16)/15.0 } else value = str.split(/\s*,\s*/).map do |s| s.to_f end end if value.size != 3 raise IncorrectInput, "You need exactly three values to make up a color" end if hls # Requires Tioga r599 value = Tioga::FigureMaker.hls_to_rgb(value) end return value end |