Class: Region

Inherits:
MLS::Model show all
Includes:
MLS::Slugger
Defined in:
lib/mls/models/region.rb

Constant Summary collapse

COUNTRY_TYPES =
["Monarchy", "Republic"]
STATE_TYPES =
["State", "Territory", "Commonwealth", "Province"]
CITY_TYPES =
["City", "Municipality", "Village", "Rural Municipality", "Town", "Resort Village", "Community Government"]

Instance Method Summary collapse

Instance Method Details

#cover_photo_url(options = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/mls/models/region.rb', line 39

def cover_photo_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]}/#{cover_photo_digest}.#{options[:format]}"
  result += "?#{url_params.to_param}" if url_params.size > 0

  result
end

#nameObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mls/models/region.rb', line 23

def name
  if common_name.try(:[], 'eng')
    common_name['eng'].is_a?(Array) ? common_name['eng'].first : common_name['eng']
  elsif official_name.try(:[], 'eng')
    official_name['eng'].is_a?(Array) ? official_name['eng'].first : official_name['eng']
  elsif common_name && common_name.size > 0
    common_name.values.first
  else
    official_name.values.first
  end
end

#tree_nameObject



35
36
37
# File 'lib/mls/models/region.rb', line 35

def tree_name
  slug.split("/").map(&:humanize).map(&:titleize).map{|r| r.length == 2 ? r.upcase : r}.reverse.join(", ")
end