Sha256: 3dfbdd9d678d4dfb7b69a59b1ba9cbbf1b6c161101daad3931e38d6d48ce4420

Contents?: true

Size: 1.02 KB

Versions: 6

Compression:

Stored size: 1.02 KB

Contents

module Oxidized
  # Used in models, contains convenience methods
  class String < String
    attr_accessor :type, :cmd, :name

    # @return [Oxidized::String] copy of self with last line removed
    def cut_tail(lines = 1)
      Oxidized::String.new each_line.to_a[0..-1 - lines].join
    end

    # @return [Oxidized::String] copy of self with first line removed
    def cut_head(lines = 1)
      Oxidized::String.new each_line.to_a[lines..-1].join
    end

    # @return [Oxidized::String] copy of self with first and last lines removed
    def cut_both(head = 1, tail = 1)
      Oxidized::String.new each_line.to_a[head..-1 - tail].join
    end

    # sets @cmd and @name unless @name is already set
    def set_cmd(command)
      @cmd = command
      @name ||= @cmd.to_s.strip.gsub(/\s+/, '_') # what to do when command is proc? #to_s seems ghetto
    end

    def initialize(str = '')
      super
      return unless str.class == Oxidized::String

      @cmd  = str.cmd
      @name = str.name
      @type = str.type
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
oxidized-0.28.0 lib/oxidized/string.rb
oxidized-0.27.0 lib/oxidized/string.rb
oxidized-0.26.3 lib/oxidized/string.rb
oxidized-0.26.2 lib/oxidized/string.rb
oxidized-0.26.1 lib/oxidized/string.rb
oxidized-0.26.0 lib/oxidized/string.rb