Module: IMW::Schemes::Remote::RemoteFile

Defined in:
lib/imw/schemes/remote.rb

Instance Method Summary collapse

Instance Method Details

#ioStringIO

Return the IO object for this remote file.

The mode of this resource is ignored.

Returns:

  • (StringIO)


67
68
69
70
# File 'lib/imw/schemes/remote.rb', line 67

def io
  require 'open-uri'
  @io ||= open(uri.to_s)              # ignore mode
end

#load {|String| ... } ⇒ Array

Return the lines of this remote file.

If passed a block then yield each line to the block.

Yields:

  • (String)

    each line of this remote file

Returns:

  • (Array)

    the lines of this remote file



85
86
87
88
89
90
91
92
93
# File 'lib/imw/schemes/remote.rb', line 85

def load &block
  if block_given?
    io.each do |line|
      yield line
    end
  else
    read.split("\n")
  end
end

#map {|String| ... } ⇒ Object

Map over the lines in this remote file.

Yields:

  • (String)

    each line of the file



98
99
100
# File 'lib/imw/schemes/remote.rb', line 98

def map &block
  io.map(&block)
end

#readString

Read the contents of this remote file.

Returns:



75
76
77
# File 'lib/imw/schemes/remote.rb', line 75

def read
  io.read
end