class Object

Public Instance Methods

first(*args) click to toggle source
# File lib/uga_uga.rb, line 187
def first *args
  l!.split.first.split(*args).first.strip
end
grab_all() click to toggle source
# File lib/uga_uga.rb, line 229
def grab_all
  blok = []
  while !@lines.empty?
    blok << shift
  end

  blok
end
grab_all_or_until(period) click to toggle source
# File lib/uga_uga.rb, line 238
def grab_all_or_until period
  grab_until period, :close_optional
end
grab_until(period, *opts) click to toggle source
# File lib/uga_uga.rb, line 242
def grab_until period, *opts
  new_cmd  = nil
  blok     = []
  found    = false
  line_num = @line_num

  is_line = period.is_a?(Regexp) ? period : /\A#{Regexp.escape period}\ *\Z/

  while !found && (l = shift)
    if !(found =l[is_line])
      blok << l
    end
  end

  if !found && !opts.include?(:close_optional)
    fail ArgumentError, "Missing from around line number: #{line_num}: #{period.inspect}\n#{blok.join "\n"}"
  end

  blok
end
head?(str_or_rxp) click to toggle source
# File lib/uga_uga.rb, line 209
def head? str_or_rxp
  rxp = if str_or_rxp.is_a?(String)
          e = Regexp.escape str_or_rxp
          /\A\ *#{e}/
        else
          str_or_rxp
        end
  l![rxp]
end
run(*args) click to toggle source
# File lib/uga_uga.rb, line 263
       def run *args
  return(Uga_Uga.new(*args, &@instruct)) unless args.empty?
  return @stack unless @stack.empty?

  while !@lines.empty?
    size = @lines.size
    num = line_num
    catch(:skip) do
      result = instance_eval(&@instruct)
      if result.is_a?(Hash)
        @stack << result
        @stack.last[:line_num] = num
      end
    end
    shift if size == @lines.size
  end

  @stack.each { |h|
    next if !h[:raw] || h[:done?]

    if h[:type] == String
      h[:output] = h[:raw].join("\n")
      h.delete :raw
      next
    end

    if h[:type] == Array
      h[:output] = h[:raw]
      h.delete :raw
      next
    end

    h[:output] = Uga_Uga.new(h.delete(:raw), h[:line_num], self, &@instruct).stack
  }
end
save_as(cmd, data = nil) click to toggle source
# File lib/uga_uga.rb, line 195
def save_as cmd, data = nil
  @stack.last[:type] = cmd
  if data
    @stack.<<( @stack.pop.merge(data) )
  end
  @stack.last
end
shift() click to toggle source
# File lib/uga_uga.rb, line 203
def shift
  @old << @lines.shift
  @line_num = @line_num + 1
  @old.last
end
skip() click to toggle source
# File lib/uga_uga.rb, line 179
def skip
  throw :skip
end
split(*args) click to toggle source
# File lib/uga_uga.rb, line 191
def split *args
  l!.split *args
end
tail?(str_or_rxp) click to toggle source
# File lib/uga_uga.rb, line 219
def tail? str_or_rxp
  rxp = if str_or_rxp.is_a?(String)
          e = Regexp.escape str_or_rxp
          /#{e}\ *\z/
        else
          str_or_rxp
        end
  l![rxp]
end
white?() click to toggle source
# File lib/uga_uga.rb, line 183
def white?
  l!.strip.empty?
end