Class: Image

Inherits:
Document show all
Defined in:
lib/mls/document.rb

Instance Method Summary collapse

Methods inherited from Document

#aspect_ratio, create, find_matching, #height, #path, #width

Instance Method Details

#url(options = {}) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/mls/document.rb', line 63

def url(options={})
  options.reverse_merge!({
    :style => nil,
    :bg => nil,
    :protocol => 'https',
    :format => "jpg",
    :host => MLS.image_host
  });

  url_params = {s: options[:style], bg: options[:bg]}.select{ |k, v| v }

  if options[:protocol] == :relative # Protocol Relative
    result = '//'
  else options[:protocol]
    result = "#{options[:protocol]}://"
  end

  result += "#{options[:host]}/#{hash_key}.#{options[:format]}"
  result += "?#{url_params.to_param}" if url_params.size > 0

  result
end