Class: VTools::ThumbsOptions
- Inherits:
-
Hash
- Object
- Hash
- VTools::ThumbsOptions
- Includes:
- SharedMethods
- Defined in:
- lib/vtools/thumbs_options.rb
Overview
options for the thumbnailer
Instance Method Summary collapse
-
#[]=(index, value) ⇒ Object
redefine native method for more readable options.
-
#initialize(options = {}) ⇒ ThumbsOptions
constructor
A new instance of ThumbsOptions.
-
#parse!(options) ⇒ Object
options parser.
- #to_s ⇒ Object
Methods included from SharedMethods
Methods included from SharedMethods::Common
#config, #fix_encoding, #generate_path, #hash_to_obj, #json_to_obj, #keys_to_sym, #log, #logger=, #network_call, #parse_json, #path_generator
Constructor Details
#initialize(options = {}) ⇒ ThumbsOptions
Returns a new instance of ThumbsOptions.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/vtools/thumbs_options.rb', line 9 def initialize = {} @ignore = [:thumb_count, :thumb_start_point, :quality, :width, :time, :postfix] # default values merge!( :thumb_count => 0, :thumb_start_point => 0, ) parse! end |
Instance Method Details
#[]=(index, value) ⇒ Object
redefine native method for more readable options
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/vtools/thumbs_options.rb', line 23 def []= index, value case when [:quality, :q].include?(index) former = {:q => value, :quality => value} when [:width, :s].include?(index) former = {:s => value, :width => value} when [:time, :t].include?(index) former = {:t => value, :time => value} else return super end merge! former value end |
#parse!(options) ⇒ Object
options parser
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/vtools/thumbs_options.rb', line 47 def parse! case # predefined when .is_a?(String) && CONFIG[:thumb_set].include?(.to_sym) # get config data s, q, count, start_point = CONFIG[:thumb_set][.to_sym] = {:thumb_count => count, :thumb_start_point => start_point, :s => s, :q => q} # niether string nor hash.. when !.is_a?(Hash) raise ConfigError, "Options should be a Hash or String (predefined set)" # convert keys to symbols else = keys_to_sym # check inline predefined parse! .delete(:set) if .has_key? :set end perform merge! end |
#to_s ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/vtools/thumbs_options.rb', line 38 def to_s params = collect do |key, value| "-#{key} #{value}" unless @ignore.include?(key) end.compact params.join " " end |