Class: HasFilepickerImage::UrlBuilder::ApiOptions

Inherits:
HashWithIndifferentAccess
  • Object
show all
Defined in:
lib/has_filepicker_image/url_builder.rb

Constant Summary collapse

CONVERSION_OPTIONS =
[:w, :h, :fit]
RETRIEVAL_OPTIONS =
[:dl, :cache]
DEFAULT_OPTIONS =
{:cache => true, :dl => 'false', :fit => 'max'}
ALL_OPTIONS =
RETRIEVAL_OPTIONS + CONVERSION_OPTIONS

Instance Method Summary collapse

Constructor Details

#initialize(styles, hash_or_style = {}, hash = {}) ⇒ ApiOptions

Returns a new instance of ApiOptions.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/has_filepicker_image/url_builder.rb', line 36

def initialize(styles, hash_or_style = {}, hash = {})
  @styles = styles

  options = if hash_or_style.is_a?(Hash)
    hash_or_style.assert_valid_keys(*ALL_OPTIONS)
    hash_or_style
  else
    hash.assert_valid_keys(*ALL_OPTIONS)
    style_api_options(hash_or_style).merge(hash)
  end

  merge! options
  merge! defaults.except *options.keys.map(&:to_sym)
end

Instance Method Details

#with_conversion_options?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/has_filepicker_image/url_builder.rb', line 51

def with_conversion_options?
  (keys.map(&:to_sym) & CONVERSION_OPTIONS).present?
end