Sha256: e2bdd58751950a1d72713b6468f74abf93b9c43898c837fede7021f62b5d3892
Contents?: true
Size: 1.48 KB
Versions: 5
Compression:
Stored size: 1.48 KB
Contents
module RemoteUnix # outputer to parse output from echoed commands piped into script/console class RailsConsoleOutput attr_reader :unparsed def initialize(out) @unparsed = out end # given a generic output item from script/console such as: # some prior items # => [id1, id2, id3] # transform the string to array # when we have STDOUT comming back from ssh session in format # [1,2,3] translate the string to a ruby Array obj def to_a unless @unparsed.grep(/.*\[.*\]/).nitems > 0 raise ArgumentError, "Tried to convert output to_a when not in correct format" end @unparsed.to_s.split(/\n/).to_s.split('=>').last.gsub(/[\[\]" ]/, '').split('>>').first.split(',') end def format out = @unparsed.to_s.split(/\n/).to_s.split('=>').last.gsub(/[\[\] "]/, '').split('>>') unless out.nitems > 0 return nil end # if we get here we found a result to return out.first end end class GenericShellOutput # return an array for the output executed excluding any other # control information, such as command executed or shell prompt def self.to_lines(out, command_executed) lines = out.first[command_executed.length..out.first.length].split(/\n/) # empty array elem from stripping out command executed, deleting lines.delete_at(0) # last item will be shell prompt, delete lines.delete_at(lines.length-1) lines end end end
Version data entries
5 entries across 5 versions & 1 rubygems