Class: SchemeOption
- Inherits:
-
Object
- Object
- SchemeOption
- Defined in:
- lib/color/coloryze.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#cls ⇒ Object
Returns the value of attribute cls.
-
#desc ⇒ Object
Returns the value of attribute desc.
-
#option ⇒ Object
Returns the value of attribute option.
-
#params ⇒ Object
Returns the value of attribute params.
-
#re ⇒ Object
Returns the value of attribute re.
-
#stype ⇒ Object
Returns the value of attribute stype.
Instance Method Summary collapse
- #create_hue(val) ⇒ Object
-
#initialize(stype, desc, cls, *params) ⇒ SchemeOption
constructor
A new instance of SchemeOption.
- #set_args(args) ⇒ Object
- #to_s ⇒ Object
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
#args ⇒ Object
Returns the value of attribute args.
17 18 19 |
# File 'lib/color/coloryze.rb', line 17 def args @args end |
#cls ⇒ Object
Returns the value of attribute cls.
17 18 19 |
# File 'lib/color/coloryze.rb', line 17 def cls @cls end |
#desc ⇒ Object
Returns the value of attribute desc.
17 18 19 |
# File 'lib/color/coloryze.rb', line 17 def desc @desc end |
#option ⇒ Object
Returns the value of attribute option.
17 18 19 |
# File 'lib/color/coloryze.rb', line 17 def option @option end |
#params ⇒ Object
Returns the value of attribute params.
17 18 19 |
# File 'lib/color/coloryze.rb', line 17 def params @params end |
#re ⇒ Object
Returns the value of attribute re.
17 18 19 |
# File 'lib/color/coloryze.rb', line 17 def re @re end |
#stype ⇒ Object
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_s ⇒ Object
50 51 52 |
# File 'lib/color/coloryze.rb', line 50 def to_s [ @stype, @desc, @cls, @re ].join(" ") end |