Class: Spritely::Collection

Inherits:
Struct
  • Object
show all
Defined in:
lib/spritely/collection.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#filesObject

Returns the value of attribute files

Returns:

  • (Object)

    the current value of files



4
5
6
# File 'lib/spritely/collection.rb', line 4

def files
  @files
end

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



4
5
6
# File 'lib/spritely/collection.rb', line 4

def options
  @options
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

#heightObject



37
38
39
# File 'lib/spritely/collection.rb', line 37

def height
  heights.reduce(:+)
end

#imagesObject



11
12
13
# File 'lib/spritely/collection.rb', line 11

def images
  image_sets.flat_map(&:images)
end

#last_modification_timeObject



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

#widthObject



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