Class: ODDB::View::VCard

Inherits:
HtmlGrid::Component show all
Defined in:
src/view/vcard.rb

Direct Known Subclasses

Doctors::VCard, Hospitals::VCard

Instance Method Summary (collapse)

Methods inherited from HtmlGrid::Component

#additional_javascripts, #dynamic_html

Instance Method Details

- (Object) addr_str(addr, text_key, div)



23
24
25
26
27
# File 'src/view/vcard.rb', line 23

def addr_str(addr, text_key, div)
  text_key \
    + [addr.street, addr.number].compact.join(' ') \
    + div + addr.city + div*2 + addr.plz
end

- (Object) addresses



13
14
15
16
17
18
19
20
21
22
# File 'src/view/vcard.rb', line 13

def addresses
  @model.addresses.inject([]) { |inj, addr| 
    inj += get_fons(addr.fon, "TEL;WORK;VOICE:")
    inj += get_fons(addr.fax, "TEL;WORK;FAX:")
    type = (addr.type == :work) ? 'WORK' : 'POSTAL'
    inj.push(addr_str(addr, "ADR;#{type};CHARSET=UTF-8:;;", ';'))
    inj.push(addr_str(addr, "LABEL;#{type};CHARSET=UTF-8:;;", ' '))
    inj
  }
end

- (Object) email



36
37
38
39
40
# File 'src/view/vcard.rb', line 36

def 
  if( = @model.)
    ["EMAIL;TYPE=internet:" + ]
  end
end

- (Object) get_fons(fons, text_key)



55
56
57
58
59
60
# File 'src/view/vcard.rb', line 55

def get_fons(fons, text_key)
  (fons || []).inject([]) { |inj, num|
    inj.push(text_key  + num.to_s)
    inj
  }
end

- (Object) get_value(key)



52
53
54
# File 'src/view/vcard.rb', line 52

def get_value(key)
  self.send(key) || []
end

- (Object) http_headers



28
29
30
31
32
33
34
35
# File 'src/view/vcard.rb', line 28

def http_headers
  filename = get_filename
  filename = prepare(filename)
  {
    'Content-Type' =>  'text/x-vCard',  
    'Content-Disposition'  => "attachment; filename=#{filename}",
  }
end

- (Object) init



10
11
12
# File 'src/view/vcard.rb', line 10

def init
  @content = [:addresses]
end

- (Object) name



61
62
63
64
65
66
# File 'src/view/vcard.rb', line 61

def name
  [
    "FN;CHARSET=UTF-8:" + @model.name,
    "N;CHARSET=UTF-8:" + @model.name,
  ]
end

- (Object) prepare(str)



72
73
74
# File 'src/view/vcard.rb', line 72

def prepare(str)
  ODDB.search_term(str)
end

- (Object) title



67
68
69
70
71
# File 'src/view/vcard.rb', line 67

def title
  if(title = @model.title)
    ["TITLE;CHARSET=UTF-8:" + title]
  end
end

- (Object) to_html(context)



41
42
43
44
45
46
47
48
49
50
51
# File 'src/view/vcard.rb', line 41

def to_html(context)
  vcard = [
    "BEGIN:vCard",
    "VERSION:3.0",
  ]
  @content.each { |key|
    vcard += get_value(key)
  }
  vcard.push("END:vCard")
  vcard.join("\n")
end