Class: VTools::ThumbsOptions

Inherits:
Hash
  • Object
show all
Includes:
SharedMethods
Defined in:
lib/vtools/thumbs_options.rb

Overview

options for the thumbnailer

Instance Method Summary collapse

Methods included from SharedMethods

included

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 options = {}

  @ignore = [:thumb_count, :thumb_start_point, :quality, :width, :time, :postfix]
  # default values
  merge!(
    :thumb_count        => 0,
    :thumb_start_point  => 0,
  )

  parse! options
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! options

  case
  # predefined
  when options.is_a?(String) && CONFIG[:thumb_set].include?(options.to_sym)
    # get config data
    s, q, count, start_point = CONFIG[:thumb_set][options.to_sym]
    options = {:thumb_count => count, :thumb_start_point => start_point, :s => s, :q => q}

  # niether string nor hash..
  when !options.is_a?(Hash)
    raise ConfigError, "Options should be a Hash or String (predefined set)"
  # convert keys to symbols
  else
    options = keys_to_sym options
    # check inline predefined
    parse! options.delete(:set) if options.has_key? :set
  end

  perform options
  merge! options
end

#to_sObject



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