class CTioga2::MetaBuilder::Types::SetParameter

A Type used for sets for Graphics::Styles::CircularArray objects.

todo write a gradient stuff !!!

Public Class Methods

new(type) click to toggle source
# File lib/ctioga2/metabuilder/types/lists.rb, line 184
def initialize(type)
  super
  @separator = /\s*\|\s*/
  @separator_out = '|'
end

Public Instance Methods

string_to_type_internal(str) click to toggle source
# 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() click to toggle source
# File lib/ctioga2/metabuilder/types/lists.rb, line 190
def type_name
  return 'set'
end