Sha256: 920ab572ec9ea997097144e36d510c440cb1622bb13713f0a6197c652f3aabd9

Contents?: true

Size: 1.02 KB

Versions: 4

Compression:

Stored size: 1.02 KB

Contents

module GitWrapper
  module Results
    class StatusPorcelain
      attr_reader :file_name
      attr_reader :original_file_name
      attr_reader :status
      attr_reader :staged_for_commit

      def initialize(file_name, original_file_name, status, staged_for_commit)
        @file_name = file_name
        @original_file_name = original_file_name
        @status = status
        @staged_for_commit = staged_for_commit
      end

      def self.parse(text)
        StatusPorcelain.new parse_file_name(text), parse_original_file_name(text), parse_status(text), parse_staged_for_commit(text)
      end

      private

      def self.parse_file_name(text)
        text[3..text.length].gsub("\"", "").split(' -> ').last
      end

      def self.parse_original_file_name(text)
        text[3..text.length].gsub("\"", "").split(' -> ').first
      end

      def self.parse_status(text)
        FileStatus.value_of text[0..2].strip
      end

      def self.parse_staged_for_commit(text)
        text[1..2].strip.empty?
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
git_wrapper-1.1.2 lib/git_wrapper/results/status_porcelain.rb
git_wrapper-1.1.1 lib/git_wrapper/results/status_porcelain.rb
git_wrapper-1.1.0 lib/git_wrapper/results/status_porcelain.rb
git_wrapper-1.0.3 lib/git_wrapper/results/status_porcelain.rb