Class: Swatchman::Palette
- Inherits:
-
Object
- Object
- Swatchman::Palette
- Defined in:
- lib/swatchman/palette.rb
Instance Attribute Summary collapse
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
-
#initialize(histogram, size) ⇒ Palette
constructor
A new instance of Palette.
- #swatches ⇒ Object
- #total ⇒ Object
Constructor Details
#initialize(histogram, size) ⇒ Palette
Returns a new instance of Palette.
7 8 9 10 |
# File 'lib/swatchman/palette.rb', line 7 def initialize(histogram, size) @histogram = histogram @size = size end |
Instance Attribute Details
#size ⇒ Object (readonly)
Returns the value of attribute size.
5 6 7 |
# File 'lib/swatchman/palette.rb', line 5 def size @size end |
Instance Method Details
#swatches ⇒ Object
12 13 14 15 16 |
# File 'lib/swatchman/palette.rb', line 12 def swatches histogram_swatches.sort_by do |swatch| swatch.frequency / total end.reverse.slice(0, size) end |
#total ⇒ Object
18 19 20 |
# File 'lib/swatchman/palette.rb', line 18 def total @total ||= histogram_swatches.map(&:frequency).reduce(:+).to_f end |