Open a layout file from url

Hi everyone, I need to open a layout file from a url.
I know that opening a file from a url is as simple as doing this:

doc = open('file.layout', 'wb') do |file|
     data << open("url/file.layout").read

but then, I need to use this file as a Layout format using his API, so I need to convert this file to Layout doc (Layout::Document…) to do something like this:

defs = doc.auto_text_definitions

The idea is to do this:

doc ='file.layout', 'wb') do |file|
   data << open("url/file.layout").read

but open method from layout’s api does not accept 2 arguments

Any idea?

Isn’t it even simpler ?

doc =
defs = doc.auto_text_definitions
  ### do something with defn e.g.
  puts d.tag
  puts d.custom_text if d.type==Layout::AutoTextDefinition::TYPE_CUSTOM_TEXT
  ### etc...

There are dozens for methods etc…

doc =

No, It’s not a path, I have to open it from a URL (http://…file.layout)

You could download the .Layout file from the URL into your Temp folder ?
Then you do have a file path from which you can read its data, as before…

Why do you have to open it from the URL ?
Why not download it first ??

If the open method doesn’t support paths I agree with TIG that downloading a temporary file is the reasonable thing to do.

Here’s the code I use to generate a unique path for a temporary file.

# Generate temp file path.
# @param extension [String, nil]
# @return [String]
def self.generate_temp_path(extension = nil)
  t ="%Y%m%d")
  filename = "#{t}-#{$PID}-#{rand(0x100000000).to_s(36)}"
  filename << extension if extension

  File.join(Dir.tmpdir, filename)

Or, use tempfile