Class: Wechat::LocalResource
- Inherits:
-
Object
- Object
- Wechat::LocalResource
- Defined in:
- lib/wechat/local_resource.rb
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #encoding ⇒ Object
- #file ⇒ Object
-
#initialize(uri) ⇒ LocalResource
constructor
A new instance of LocalResource.
- #io ⇒ Object
- #tmp_filename ⇒ Object
- #tmp_folder ⇒ Object
Constructor Details
#initialize(uri) ⇒ LocalResource
Returns a new instance of LocalResource.
6 7 8 |
# File 'lib/wechat/local_resource.rb', line 6 def initialize(uri) @uri = uri end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
4 5 6 |
# File 'lib/wechat/local_resource.rb', line 4 def uri @uri end |
Instance Method Details
#encoding ⇒ Object
22 23 24 25 |
# File 'lib/wechat/local_resource.rb', line 22 def encoding io.rewind io.read.encoding end |
#file ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/wechat/local_resource.rb', line 10 def file @file ||= Tempfile.new(tmp_filename, tmp_folder, encoding: encoding).tap do |f| io.rewind f.write(io.read) f.close end end |
#io ⇒ Object
18 19 20 |
# File 'lib/wechat/local_resource.rb', line 18 def io @io ||= uri.open end |
#tmp_filename ⇒ Object
27 28 29 |
# File 'lib/wechat/local_resource.rb', line 27 def tmp_filename File.basename(uri.path) end |
#tmp_folder ⇒ Object
31 32 33 |
# File 'lib/wechat/local_resource.rb', line 31 def tmp_folder '/tmp' end |