Sha256: f01ea20003f10e89cde6cfd9242f3797d7e66ba4d43818047c38877ea84a6ee7

Contents?: true

Size: 804 Bytes

Versions: 9

Compression:

Stored size: 804 Bytes

Contents

# frozen_string_literal: true

module CrudeMutant
  class FileLoader
    class LoadError < StandardError; end

    def self.load(file_path)
      if !file_path.is_a?(String) || !File.exist?(file_path)
        raise LoadError, "Could not load file: #{file_path}"
      end

      new(file_path, File.readlines(file_path))
    end

    attr_reader :file_path

    def initialize(file_path, contents_as_array)
      @file_path = file_path
      @contents_as_array = contents_as_array
    end
    private_class_method :new

    def lines_in_file
      @contents_as_array.size
    end

    def contents_as_array
      @contents_as_array
    end

    def without_line(line_number)
      contents_as_array.slice(0, line_number) +
        contents_as_array.slice(line_number + 1, lines_in_file)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
crude-mutant-0.3.4 lib/crude_mutant/file_loader.rb
crude-mutant-0.3.3 lib/crude_mutant/file_loader.rb
crude-mutant-0.3.2 lib/crude_mutant/file_loader.rb
crude-mutant-0.3.1 lib/crude_mutant/file_loader.rb
crude-mutant-0.3.0 lib/crude_mutant/file_loader.rb
crude-mutant-0.2.3 lib/crude_mutant/file_loader.rb
crude-mutant-0.2.2 lib/crude_mutant/file_loader.rb
crude-mutant-0.2.1 lib/crude_mutant/file_loader.rb
crude-mutant-0.2.0 lib/crude_mutant/file_loader.rb