Class: QuickResponse::Base

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

Direct Known Subclasses

Call, Email, Geo, Maps, Sms, Text, Url

Constant Summary collapse

GOOGLE_CHART_API =
"http://chart.apis.google.com/chart"
DEFAULT_OPTIONS =
{ :size => 256 }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Base

Returns a new instance of Base.



9
10
11
12
13
14
15
# File 'lib/quick_response/base.rb', line 9

def initialize(*args)
  # Extract options
  options = args.last.is_a?(Hash) ? DEFAULT_OPTIONS.merge(args.pop) : DEFAULT_OPTIONS

  @content = to_format(*args)
  @size    = options[:size]
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



6
7
8
# File 'lib/quick_response/base.rb', line 6

def content
  @content
end

#sizeObject

Returns the value of attribute size.



7
8
9
# File 'lib/quick_response/base.rb', line 7

def size
  @size
end

Instance Method Details

#image_urlObject



21
22
23
# File 'lib/quick_response/base.rb', line 21

def image_url
  uri.to_s
end

#save(location) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/quick_response/base.rb', line 25

def save(location)
  Net::HTTP.start(uri.host) do |http|
    resp = http.get(image_url)
    open(location, 'wb') do |file|
      file.write(resp.body)
    end
  end
end