Class: EhbGameLib::Palettes::Palette
- Inherits:
-
Object
- Object
- EhbGameLib::Palettes::Palette
- Defined in:
- lib/ehb_game_lib/palettes/palette.rb
Direct Known Subclasses
Instance Attribute Summary collapse
- #colors ⇒ Array<Gosu::Color> readonly
Class Method Summary collapse
Instance Method Summary collapse
- #[](index) ⇒ EhbGameLib::Palettes::Color
- #color(index) ⇒ EhbGameLib::Palettes::Color
-
#initialize(colors) ⇒ Palette
constructor
A new instance of Palette.
- #sub(*indexes) ⇒ EhbGameLib::Palettes::Palette
- #sub_class ⇒ Object
Constructor Details
#initialize(colors) ⇒ Palette
Returns a new instance of Palette.
19 20 21 22 23 24 25 26 |
# File 'lib/ehb_game_lib/palettes/palette.rb', line 19 def initialize(colors) colors.each_with_index do |color, index| unless color.is_a?(::EhbGameLib::Palettes::Color) raise "\##{index} is not a Palette::Color (#{color})" end end @colors = colors.to_a.freeze end |
Instance Attribute Details
#colors ⇒ Array<Gosu::Color> (readonly)
17 18 19 |
# File 'lib/ehb_game_lib/palettes/palette.rb', line 17 def colors @colors end |
Class Method Details
.from_file(file_path) ⇒ EhbGameLib::Palettes::Palette
11 12 13 |
# File 'lib/ehb_game_lib/palettes/palette.rb', line 11 def from_file(file_path) new(::EhbGameLib::Palettes::Color.array_from_file(file_path)) end |
Instance Method Details
#[](index) ⇒ EhbGameLib::Palettes::Color
34 35 36 |
# File 'lib/ehb_game_lib/palettes/palette.rb', line 34 def [](index) colors.fetch(index) end |
#color(index) ⇒ EhbGameLib::Palettes::Color
29 30 31 |
# File 'lib/ehb_game_lib/palettes/palette.rb', line 29 def color(index) colors.fetch(index) end |
#sub(*indexes) ⇒ EhbGameLib::Palettes::Palette
39 40 41 |
# File 'lib/ehb_game_lib/palettes/palette.rb', line 39 def sub(*indexes) sub_class.new(indexes.map { |index| color(index) }) end |
#sub_class ⇒ Object
43 44 45 |
# File 'lib/ehb_game_lib/palettes/palette.rb', line 43 def sub_class ::EhbGameLib::Palettes::Palette end |