Class: SchemeOption

Inherits:
Object
  • Object
show all
Defined in:
lib/color/coloryze.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stype, desc, cls, *params) ⇒ SchemeOption

Returns a new instance of SchemeOption.



19
20
21
22
23
24
25
26
27
28
# File 'lib/color/coloryze.rb', line 19

def initialize(stype, desc, cls, *params)
  @stype  = stype
  @desc   = desc
  @cls    = cls
  @params = params
  @option = '--' + stype + "=" + params.collect { |arg| arg.to_s.upcase                          }.join(',')
  restr   = '^' + '--' + stype + "=" + params.collect { |arg| arg == :hue ? '(\#?\w+)' : '(\d+)' }.join(',') + '$'  # '$
  @re     = Regexp.new(restr)
  @args   = Array.new
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



17
18
19
# File 'lib/color/coloryze.rb', line 17

def args
  @args
end

#clsObject

Returns the value of attribute cls.



17
18
19
# File 'lib/color/coloryze.rb', line 17

def cls
  @cls
end

#descObject

Returns the value of attribute desc.



17
18
19
# File 'lib/color/coloryze.rb', line 17

def desc
  @desc
end

#optionObject

Returns the value of attribute option.



17
18
19
# File 'lib/color/coloryze.rb', line 17

def option
  @option
end

#paramsObject

Returns the value of attribute params.



17
18
19
# File 'lib/color/coloryze.rb', line 17

def params
  @params
end

#reObject

Returns the value of attribute re.



17
18
19
# File 'lib/color/coloryze.rb', line 17

def re
  @re
end

#stypeObject

Returns the value of attribute stype.



17
18
19
# File 'lib/color/coloryze.rb', line 17

def stype
  @stype
end

Instance Method Details

#create_hue(val) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/color/coloryze.rb', line 40

def create_hue(val)
  if Color::RGB.matches_rgb_string?(val)
    Color::RGB.new(val).to_hsb.hue
  elsif md = %r{^\d+$}.match(val)
    val.to_i
  else
    raise RuntimeErro.new("invalid value for hue: #{val}")
  end
end

#set_args(args) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/color/coloryze.rb', line 30

def set_args(args)
  (0 ... args.length).each do |idx|
    if @params[idx] == :hue
      @args << create_hue(args[idx])
    else
      @args << args[idx].to_i
    end
  end
end

#to_sObject



50
51
52
# File 'lib/color/coloryze.rb', line 50

def to_s
  [ @stype, @desc, @cls, @re ].join(" ")
end