Class: GoogleQR
- Inherits:
-
Object
- Object
- GoogleQR
- Defined in:
- lib/google-qr.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#encoding ⇒ Object
Returns the value of attribute encoding.
-
#error_correction ⇒ Object
Returns the value of attribute error_correction.
-
#html_options ⇒ Object
Returns the value of attribute html_options.
-
#margin ⇒ Object
Returns the value of attribute margin.
-
#size ⇒ Object
Returns the value of attribute size.
-
#use_https ⇒ Object
Returns the value of attribute use_https.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ GoogleQR
constructor
A new instance of GoogleQR.
- #render ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ GoogleQR
Returns a new instance of GoogleQR.
7 8 9 10 11 12 13 14 |
# File 'lib/google-qr.rb', line 7 def initialize(opts={}) = { :size => "100x100", :use_https => true }.merge!(opts) .each {|key,value| self.send("#{key}=", value) } end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/google-qr.rb', line 5 def data @data end |
#encoding ⇒ Object
Returns the value of attribute encoding.
5 6 7 |
# File 'lib/google-qr.rb', line 5 def encoding @encoding end |
#error_correction ⇒ Object
Returns the value of attribute error_correction.
5 6 7 |
# File 'lib/google-qr.rb', line 5 def error_correction @error_correction end |
#html_options ⇒ Object
Returns the value of attribute html_options.
5 6 7 |
# File 'lib/google-qr.rb', line 5 def @html_options end |
#margin ⇒ Object
Returns the value of attribute margin.
5 6 7 |
# File 'lib/google-qr.rb', line 5 def margin @margin end |
#size ⇒ Object
Returns the value of attribute size.
5 6 7 |
# File 'lib/google-qr.rb', line 5 def size @size end |
#use_https ⇒ Object
Returns the value of attribute use_https.
5 6 7 |
# File 'lib/google-qr.rb', line 5 def use_https @use_https end |
Instance Method Details
#render ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/google-qr.rb', line 28 def render if self.size height, width = self.size.split('x') dimensions = " height='#{height}' width='#{width}' " else dimensions = nil end if self. = "" self..each do |k, v| if k.to_s.length > 0 && v.to_s.length > 0 += k.to_s + "='" + v.to_s + "' " end end else = nil end "<img src='#{self.to_s}'#{dimensions}#{}/>" end |
#to_s ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/google-qr.rb', line 16 def to_s if self.data params = ["chl=#{escape_string(self.data)}"] params << "chs=#{self.size}" params << "choe=#{self.encoding}" if self.encoding params << error_correction_params if error_correction_param? base_url + params.join("&") else raise "Attribute @data is required for GoogleQR code" end end |