Class: Wechat::LocalResource

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#uriObject (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

#encodingObject



22
23
24
25
# File 'lib/wechat/local_resource.rb', line 22

def encoding
  io.rewind
  io.read.encoding
end

#fileObject



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

#ioObject



18
19
20
# File 'lib/wechat/local_resource.rb', line 18

def io
  @io ||= uri.open
end

#tmp_filenameObject



27
28
29
# File 'lib/wechat/local_resource.rb', line 27

def tmp_filename
  File.basename(uri.path)
end

#tmp_folderObject



31
32
33
# File 'lib/wechat/local_resource.rb', line 31

def tmp_folder
  '/tmp'
end