Class: QuickResponse::Base
- Inherits:
-
Object
- Object
- QuickResponse::Base
- Defined in:
- lib/quick_response/base.rb
Constant Summary collapse
- GOOGLE_CHART_API =
"http://chart.apis.google.com/chart"- DEFAULT_OPTIONS =
{ :size => 256 }
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#size ⇒ Object
Returns the value of attribute size.
Instance Method Summary collapse
- #image_url ⇒ Object
-
#initialize(*args) ⇒ Base
constructor
A new instance of Base.
- #save(location) ⇒ Object
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 = args.last.is_a?(Hash) ? DEFAULT_OPTIONS.merge(args.pop) : DEFAULT_OPTIONS @content = to_format(*args) @size = [:size] end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
6 7 8 |
# File 'lib/quick_response/base.rb', line 6 def content @content end |
#size ⇒ Object
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_url ⇒ Object
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 |