Class: Safai::Address

Inherits:
Object
  • Object
show all
Includes:
Carmen
Defined in:
lib/safai/address.rb

Class Method Summary collapse

Class Method Details

.country_to_s(country_iso2) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/safai/address.rb', line 7

def self.country_to_s(country_iso2)
  if !country_iso2.nil?
    cobj = Country.coded(country_iso2)
    if !cobj.blank?
      return cobj.name
    end
  end
  return ""
end

.gist(u) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/safai/address.rb', line 42

def self.gist(u)
  str = ""
  str = (u.city.blank? ? "" : u.city + ", ")
  c = Safai::Address.country_to_s(u.country_iso2)
  s = Safai::Address.state_to_s(u.country_iso2, u.subregion_iso2)
  str = str + (s.blank? ? "" : s + ", ")
  str = str + (c.blank? ? "" : c)
  return str
end

.gist_no_city(u) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/safai/address.rb', line 52

def self.gist_no_city(u)
  str = ""
  c = Safai::Address.country_to_s(u.country_iso2)
  s = Safai::Address.state_to_s(u.country_iso2, u.subregion_iso2)
  str = str + (s.blank? ? "" : s + ", ")
  str = str + (c.blank? ? "" : c)
  return str
end

.map(u, h = 300, w = 95) ⇒ Object

Google Maps Static API



63
64
65
66
67
68
69
# File 'lib/safai/address.rb', line 63

def self.map(u, h=300, w=95)
  str = ""
  str = (u.city.blank? ? "" : u.city + "++")
  c = Safai::Address.country_to_s(u.country_iso2)
  str = str + (c.blank? ? "" : c)
  return str == "" ? nil : "https://maps.google.com/maps/api/staticmap?visible=#{str}&size=#{h.to_s}x#{w.to_s}&sensor=false&maptype=terrain&markers=size:small|color:red|#{str}"
end

.state_to_s(country_iso2, state_iso2) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/safai/address.rb', line 17

def self.state_to_s(country_iso2, state_iso2)
  if !country_iso2.nil? and !state_iso2.nil?
    cobj = Country.coded(country_iso2)
    if !cobj.blank?
      sobj = cobj.subregions.coded(state_iso2)
      if !sobj.blank?
        return sobj.name
      end
    end
  end
  return ""
end

.to_s(u) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/safai/address.rb', line 30

def self.to_s(u)
  str = ""
  str = (u.addressline.blank? ? "" : u.addressline + ", ")
  str = str + (u.city.blank? ? "" : u.city + ", ")
  str = str + (u.zipcode.blank? ? "" : u.zipcode + ", ")
  c = Safai::Address.country_to_s(u.country_iso2)
  s = Safai::Address.state_to_s(u.country_iso2, u.subregion_iso2)
  str = str + (s.blank? ? "" : s + ", ")
  str = str + (c.blank? ? "" : c)
  return str
end