Class: Spritely::Collection
- Inherits:
-
Struct
- Object
- Struct
- Spritely::Collection
- Defined in:
- lib/spritely/collection.rb
Instance Attribute Summary collapse
-
#files ⇒ Object
Returns the value of attribute files.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #find(name) ⇒ Object
- #height ⇒ Object
- #images ⇒ Object
- #last_modification_time ⇒ Object
- #position! ⇒ Object
- #width ⇒ Object
Instance Attribute Details
#files ⇒ Object
Returns the value of attribute files
4 5 6 |
# File 'lib/spritely/collection.rb', line 4 def files @files end |
#options ⇒ Object
Returns the value of attribute options
4 5 6 |
# File 'lib/spritely/collection.rb', line 4 def end |
Class Method Details
.create(*args) ⇒ Object
5 6 7 8 9 |
# File 'lib/spritely/collection.rb', line 5 def self.create(*args) new(*args).tap do |collection| collection.position! end end |
Instance Method Details
#find(name) ⇒ Object
15 16 17 |
# File 'lib/spritely/collection.rb', line 15 def find(name) image_sets.find { |image_set| image_set.name == name } end |
#height ⇒ Object
37 38 39 |
# File 'lib/spritely/collection.rb', line 37 def height heights.reduce(:+) end |
#images ⇒ Object
11 12 13 |
# File 'lib/spritely/collection.rb', line 11 def images image_sets.flat_map(&:images) end |
#last_modification_time ⇒ Object
19 20 21 |
# File 'lib/spritely/collection.rb', line 19 def last_modification_time files.collect { |file| Spritely.modification_time(file) }.max end |
#position! ⇒ Object
41 42 43 44 45 46 |
# File 'lib/spritely/collection.rb', line 41 def position! image_sets.each_with_index do |image_set, index| image_set.top = heights[0..index].reduce(:+) - image_set.height image_set.position_in!(width) end end |
#width ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/spritely/collection.rb', line 23 def width return @width if @width max_width = image_sets.collect(&:width).max if image_sets.none?(&:repeated?) @width = max_width else @width = lcm = image_sets.select(&:repeated?).collect(&:width).reduce(:lcm) @width += lcm while @width < max_width end @width end |