Class: QRCodeIntent

Inherits:
Object
  • Object
show all
Defined in:
lib/qrcode_intent.rb

Defined Under Namespace

Classes: WiFi

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj = nil, event: nil, contact: nil, website: nil, wifi: nil, location: nil, debug: false) ⇒ QRCodeIntent



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/qrcode_intent.rb', line 15

def initialize(obj=nil, event: nil, contact: nil, website: nil, 
               wifi: nil, location: nil, debug: false)
  
  @debug = debug
  
  if website then
  
    add_website website
  
  elsif location
    
    add_location location
    
  elsif event 
    
    add_event event
    
  elsif contact
    
    add_contact contact

  elsif wifi
    
    add_wifi wifi
    
  else
    
    if obj.is_a? String then
      obj
    elsif obj.is_a? Hash
      obj[:start] ? add_event(obj) : add_contact(obj)
    end
    
  end
  
end

Instance Attribute Details

#to_sObject (readonly)

Returns the value of attribute to_s.



11
12
13
# File 'lib/qrcode_intent.rb', line 11

def to_s
  @to_s
end

Instance Method Details

#add_contact(obj = nil, &blk) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/qrcode_intent.rb', line 52

def add_contact(obj=nil, &blk)
  
  @to_s = if block_given? then
    
    SimpleVpim.new(:contact, &blk).to_vcard.to_s
    
  elsif obj
    
    SimpleVpim.new(obj).to_vcard.to_s
    
  end
  
end

#add_event(obj = nil, &blk) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/qrcode_intent.rb', line 66

def add_event(obj=nil, &blk)
  
  @to_s = if block_given? then
    
    SimpleVpim.new(:event, &blk).to_vevent
    
  elsif obj
    
    SimpleVpim.new(obj).to_vevent
    
  end
  
end

#add_location(s) ⇒ Object

e.g. add_location ‘55.8835644,-3.2312978’



82
83
84
# File 'lib/qrcode_intent.rb', line 82

def add_location(s)
  @to_s = 'geo:' + s
end

#add_website(s) ⇒ Object

e.g. add_website ‘news.bbc.co.uk/’



88
89
90
# File 'lib/qrcode_intent.rb', line 88

def add_website(s)
  @to_s = s
end

#add_wifi(obj = nil, &blk) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/qrcode_intent.rb', line 92

def add_wifi(obj=nil, &blk)
  
  h = if block_given? then
    
    wifi = WiFi.new(nil, 'WPA', nil)
    yield wifi
    wifi.to_h

    
  elsif obj.is_a? Hash
    
    obj
    
  end
  
  @to_s = "WIFI:S%s;T:%s;P:%s;;" % [h[:ssid], h[:type], h[:password]]
  
end

#to_svgObject



111
112
113
# File 'lib/qrcode_intent.rb', line 111

def to_svg()
  RQRCode::QRCode.new(@to_s).as_svg
end