Class: Kin::Sprites::IconSet
- Inherits:
-
Object
- Object
- Kin::Sprites::IconSet
- Includes:
- Enumerable
- Defined in:
- lib/kin/sprites.rb
Overview
A simple class which represents a list of icons (wrapper around an array).
Instance Method Summary collapse
-
#[](*slice) ⇒ Set
Returns a slice of the set.
-
#each {|String| ... } ⇒ Object
Loops through, and yields, each icon in turn.
-
#hash ⇒ String
Returns a hash for the icon list.
-
#initialize(icons) ⇒ IconSet
constructor
Creates a new IconSet instance.
-
#length ⇒ Integer
Returns the number of icons in this set.
-
#location_of(icon) ⇒ Integer
Returns the vertical offset of a given icon in a sprite.
Constructor Details
#initialize(icons) ⇒ IconSet
Creates a new IconSet instance.
24 25 26 |
# File 'lib/kin/sprites.rb', line 24 def initialize(icons) @icons = icons.uniq end |
Instance Method Details
#[](*slice) ⇒ Set
Returns a slice of the set. Note: This returns a Set, not an IconSet.
80 81 82 |
# File 'lib/kin/sprites.rb', line 80 def [](*slice) @icons[*slice] end |
#each {|String| ... } ⇒ Object
Loops through, and yields, each icon in turn.
59 60 61 |
# File 'lib/kin/sprites.rb', line 59 def each @icons.each { |i| yield i } end |
#hash ⇒ String
Returns a hash for the icon list. Assuming the list contains the same icons, and in the same order, the hash will always be the same.
90 91 92 |
# File 'lib/kin/sprites.rb', line 90 def hash Digest::SHA256.hexdigest(@icons.join("|")) end |
#length ⇒ Integer
Returns the number of icons in this set.
68 69 70 |
# File 'lib/kin/sprites.rb', line 68 def length @icons.length end |
#location_of(icon) ⇒ Integer
Returns the vertical offset of a given icon in a sprite.
46 47 48 49 50 51 52 |
# File 'lib/kin/sprites.rb', line 46 def location_of(icon) unless @icons.include?(icon) raise ArgumentError, "Icon does not appear in the list: #{icon}" end @icons.index(icon) * 40 end |