Class: CTioga2::MetaBuilder::Types::SetParameter
- Inherits:
-
ArrayParameter
- Object
- CTioga2::MetaBuilder::Type
- ArrayParameter
- CTioga2::MetaBuilder::Types::SetParameter
- Defined in:
- lib/ctioga2/metabuilder/types/lists.rb
Overview
A Type used for sets for Graphics::Styles::CircularArray objects.
todo write a gradient stuff !!!
Instance Attribute Summary
Attributes inherited from CTioga2::MetaBuilder::Type
#namespace, #namespace_lookup, #passthrough, #re_shortcuts, #shortcuts, #type
Instance Method Summary collapse
-
#initialize(type) ⇒ SetParameter
constructor
A new instance of SetParameter.
- #string_to_type_internal(str) ⇒ Object
- #type_name ⇒ Object
Methods inherited from ArrayParameter
Methods inherited from CTioga2::MetaBuilder::Type
#boolean?, #default_value, from_string, get_param_type, get_type, #option_parser_long_option, #option_parser_option, #string_to_type, type_name, #type_to_string
Constructor Details
#initialize(type) ⇒ SetParameter
Returns a new instance of SetParameter.
184 185 186 187 188 |
# File 'lib/ctioga2/metabuilder/types/lists.rb', line 184 def initialize(type) super @separator = /\s*\|\s*/ @separator_out = '|' end |
Instance Method Details
#string_to_type_internal(str) ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/ctioga2/metabuilder/types/lists.rb', line 194 def string_to_type_internal(str) multiply = nil if str =~ /(.*)\*\s*(\d+)\s*$/ multiply = $2.to_i str = $1 end if str =~ /^\s*gradient:(.+)--(.+),(\d+)\s*$/ s,e,nb = $1, $2, $3.to_i s,e = @subtype.string_to_type(s),@subtype.string_to_type(e) fact = if nb > 1 1.0/(nb - 1) # The famous off-by one... else warn { "Incorrect gradient number: '#{nb}'" } 1.0 end array = [] nb.times do |i| array << Utils::mix_objects(e,s, i * fact) end elsif str =~ /(.*)!!(\d+)(?:!!(.*))?\s*$/ # We have a mixing nb = $2.to_i fact = nb*0.01 if fact > 1.0 || fact < 0.0 error { "Invalid number for mixing: #{nb}, using 50"} fact = 0.5 end st1 = $1 st2 = $3 || 'White' # default to colors ! ar1 = string_to_type(st1) ar2 = string_to_type(st2) # Make all the sequential combinations until we fall back # on the first one. ts = ar1.size.lcm(ar2.size) ar1 *= ts/ar1.size ar2 *= ts/ar2.size arf = [] ar1.each_index do |i| arf << Utils::mix_objects(ar1[i], ar2[i], fact) end return arf else array = super end if multiply # Seems that I've finally managed to understand what zip # is useful for ! array = array.zip(*([array]*(multiply-1))).flatten(1) end return array end |
#type_name ⇒ Object
190 191 192 |
# File 'lib/ctioga2/metabuilder/types/lists.rb', line 190 def type_name return 'set' end |