Class: Spritely::Options

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

Overview

Provides a simpler method of querying a particular image’s options. Rather than each ‘Image` needing to know how to parse the keyword arguments passed into the `spritely-map` function, this simplifies and de-duplicates the passed option keys.

$application-sprite: spritely-map("application/*.png",
  $arrow-repeat: true,
  $arrow-spacing: 10px,
  $another-image-position: right,
  $spacing: 5px
);

The options passed in above will be easily accessible via an instance of this class.

options['arrow'] => {repeat: true, spacing: 10}
options['another-image'] => {position: 'right', spacing: 5}

Constant Summary collapse

GLOBAL_OPTIONS =
['spacing', 'position']

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hashObject

Returns the value of attribute hash

Returns:

  • (Object)

    the current value of hash



24
25
26
# File 'lib/spritely/options.rb', line 24

def hash
  @hash
end

Instance Method Details

#[](key) ⇒ Object



35
36
37
# File 'lib/spritely/options.rb', line 35

def [](key)
  options[key.gsub('-', '_')] || global_options
end

#cache_keyObject



27
28
29
# File 'lib/spritely/options.rb', line 27

def cache_key
  stripped_hash.to_s
end

#inspectObject



31
32
33
# File 'lib/spritely/options.rb', line 31

def inspect
  "#<Spritely::Options global_options=#{global_options} options=#{options}>"
end