Class: Gct::TempRemoteFile
- Inherits:
-
Object
- Object
- Gct::TempRemoteFile
- Defined in:
- lib/gct/temp_remote_file.rb
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #close ⇒ Object
- #encoding ⇒ Object
- #file ⇒ Object
-
#initialize(url, content) ⇒ TempRemoteFile
constructor
A new instance of TempRemoteFile.
- #io ⇒ Object
- #tmp_filename ⇒ Object
- #tmp_folder ⇒ Object
Constructor Details
#initialize(url, content) ⇒ TempRemoteFile
Returns a new instance of TempRemoteFile.
5 6 7 8 |
# File 'lib/gct/temp_remote_file.rb', line 5 def initialize(url, content) @uri = URI.parse(url) @content = content end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
3 4 5 |
# File 'lib/gct/temp_remote_file.rb', line 3 def uri @uri end |
Instance Method Details
#close ⇒ Object
19 20 21 22 |
# File 'lib/gct/temp_remote_file.rb', line 19 def close @file.close @file.unlink end |
#encoding ⇒ Object
28 29 30 31 |
# File 'lib/gct/temp_remote_file.rb', line 28 def encoding io.rewind io.read.encoding end |
#file ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/gct/temp_remote_file.rb', line 10 def file @file ||= Tempfile.open(tmp_filename, tmp_folder, encoding: encoding) do |f| puts f io.rewind f.write(io.read) f.close end end |
#io ⇒ Object
24 25 26 |
# File 'lib/gct/temp_remote_file.rb', line 24 def io @io ||= uri.open end |
#tmp_filename ⇒ Object
33 34 35 36 37 38 |
# File 'lib/gct/temp_remote_file.rb', line 33 def tmp_filename [ Pathname.new(uri.path).basename, Pathname.new(uri.path).extname ] end |
#tmp_folder ⇒ Object
40 41 42 |
# File 'lib/gct/temp_remote_file.rb', line 40 def tmp_folder Generator::GctFile.temp_folder_path end |