Class: Moo::Model::Colour
Instance Attribute Summary collapse
-
#b ⇒ Object
Returns the value of attribute b.
-
#c ⇒ Object
Returns the value of attribute c.
-
#g ⇒ Object
Returns the value of attribute g.
-
#k ⇒ Object
Returns the value of attribute k.
-
#m ⇒ Object
Returns the value of attribute m.
-
#r ⇒ Object
Returns the value of attribute r.
-
#type ⇒ Object
Returns the value of attribute type.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
- #from_json(json) ⇒ Object
-
#initialize {|_self| ... } ⇒ Colour
constructor
A new instance of Colour.
- #to_hash ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ Colour
Returns a new instance of Colour.
7 8 9 |
# File 'lib/moo/model/colour.rb', line 7 def initialize yield self if block_given? end |
Instance Attribute Details
#b ⇒ Object
Returns the value of attribute b.
5 6 7 |
# File 'lib/moo/model/colour.rb', line 5 def b @b end |
#c ⇒ Object
Returns the value of attribute c.
5 6 7 |
# File 'lib/moo/model/colour.rb', line 5 def c @c end |
#g ⇒ Object
Returns the value of attribute g.
5 6 7 |
# File 'lib/moo/model/colour.rb', line 5 def g @g end |
#k ⇒ Object
Returns the value of attribute k.
5 6 7 |
# File 'lib/moo/model/colour.rb', line 5 def k @k end |
#m ⇒ Object
Returns the value of attribute m.
5 6 7 |
# File 'lib/moo/model/colour.rb', line 5 def m @m end |
#r ⇒ Object
Returns the value of attribute r.
5 6 7 |
# File 'lib/moo/model/colour.rb', line 5 def r @r end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/moo/model/colour.rb', line 5 def type @type end |
#y ⇒ Object
Returns the value of attribute y.
5 6 7 |
# File 'lib/moo/model/colour.rb', line 5 def y @y end |
Instance Method Details
#from_json(json) ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/moo/model/colour.rb', line 77 def from_json json hash = JSON.parse json, :symbolize_names => true keys = [:type] if hash[:type] == 'RGB' keys << :r << :g << :b elsif hash[:type] == 'CMYK' keys << :c << :m << :y << :k end keys.each { |k| send (k.to_s + '=').to_sym, hash[k] } end |
#to_hash ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/moo/model/colour.rb', line 58 def to_hash if @type == 'RGB' return { :type => 'RGB', :r => @r, :g => @g, :b => @b } elsif @type == 'CMYK' return { :type => 'CMYK', :c => @c, :m => @m, :y => @y, :k => @k } end end |
#to_json ⇒ Object
54 55 56 |
# File 'lib/moo/model/colour.rb', line 54 def to_json self.to_hash.to_json end |