Class: Falu::Swatch
- Inherits:
-
Object
- Object
- Falu::Swatch
- Defined in:
- lib/falu/swatch.rb
Instance Attribute Summary collapse
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#count ⇒ Object
readonly
Returns the value of attribute count.
Class Method Summary collapse
Instance Method Summary collapse
- #+(cnt) ⇒ Object
- #-(cnt) ⇒ Object
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #as_json(options = {}) ⇒ Object
-
#initialize(color, count = 0) ⇒ Swatch
constructor
A new instance of Swatch.
- #to_a ⇒ Object
- #to_h ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
Constructor Details
Instance Attribute Details
#color ⇒ Object (readonly)
Returns the value of attribute color.
3 4 5 |
# File 'lib/falu/swatch.rb', line 3 def color @color end |
#count ⇒ Object (readonly)
Returns the value of attribute count.
3 4 5 |
# File 'lib/falu/swatch.rb', line 3 def count @count end |
Class Method Details
.dump(swatch) ⇒ Object
8 9 10 |
# File 'lib/falu/swatch.rb', line 8 def dump(swatch) swatch.as_json end |
.load(json) ⇒ Object
12 13 14 15 |
# File 'lib/falu/swatch.rb', line 12 def load(json) json.symbolize_keys! new(json[:color].values.first, json[:count]) end |
Instance Method Details
#+(cnt) ⇒ Object
35 36 37 |
# File 'lib/falu/swatch.rb', line 35 def +(cnt) self.class.new(color, (count + cnt.to_i)) end |
#-(cnt) ⇒ Object
39 40 41 |
# File 'lib/falu/swatch.rb', line 39 def -(cnt) self.class.new(color, (count - cnt.to_i)) end |
#<=>(other) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/falu/swatch.rb', line 23 def <=>(other) if count == other.count color <=> color else count <=> other.count end end |
#==(other) ⇒ Object
31 32 33 |
# File 'lib/falu/swatch.rb', line 31 def ==(other) to_s == other.to_s end |
#as_json(options = {}) ⇒ Object
59 60 61 62 |
# File 'lib/falu/swatch.rb', line 59 def as_json(={}) #{color: color.as_json, count: count} to_a end |
#to_a ⇒ Object
51 52 53 |
# File 'lib/falu/swatch.rb', line 51 def to_a [to_s, to_i] end |
#to_h ⇒ Object
55 56 57 |
# File 'lib/falu/swatch.rb', line 55 def to_h {color: to_s, count: to_i} end |
#to_i ⇒ Object
43 44 45 |
# File 'lib/falu/swatch.rb', line 43 def to_i count end |
#to_s ⇒ Object
47 48 49 |
# File 'lib/falu/swatch.rb', line 47 def to_s color.to_s end |