Sha256: f4208c9d5a6c20ddc29f41f9e966f8da41ac135787d4216469244b0a48eac731

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

module Remedy
  class Partial
    def initialize collection = Array.new
      @lines = Array.new
      self + collection
    end
    attr_accessor :lines

    def + new_lines
      new_lines.each do |line|
        self << line
      end
    end

    def << line
      reset_width!
      @lines += clean line unless line.nil? || line.empty?
    end

    def first
      lines.first
    end

    def last
      lines.last
    end

    def length
      lines.length
    end

    def width
      @width ||= lines.max{|line| line.length }.length
    end

    def size
      Size.new length, width
    end

    def to_a
      lines
    end

    def to_s
      lines.join '\n'
    end

    def join seperator
      lines.join seperator
    end

    def excerpt lines_range, width_range
      self.class.new lines[lines_range].map { |line| line[width_range] }
    end

    protected

    def reset_width!
      @width = nil
    end

    def clean line
      Array split(line)
    end

    def split line
      line.split /\r\n|\n\r|\n|\r/
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
remedy-0.2.0 lib/remedy/partial.rb
remedy-0.1.2 lib/remedy/partial.rb
remedy-0.1.1 lib/remedy/partial.rb