Sha256: 4d526b76e6f39dcbd14401c241e7860076622d08f15a84e224c104e5518aba16

Contents?: true

Size: 1.02 KB

Versions: 6

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 }
    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

6 entries across 6 versions & 1 rubygems

Version Path
remedy-0.1.0 lib/remedy/partial.rb
remedy-0.0.5 lib/remedy/partial.rb
remedy-0.0.4 lib/remedy/partial.rb
remedy-0.0.4.pre lib/remedy/partial.rb
remedy-0.0.3 lib/remedy/partial.rb
remedy-0.0.3.pre lib/remedy/partial.rb