module GitStatistics
  class Branches

    CURRENT_BRANCH = /\A\*\s/
    NO_BRANCH = /no branch/i

    def self.all
      list.collect { |branch| branch.sub(CURRENT_BRANCH, "") }
    end

    def self.current
      return '(none)' if detached?
      list.detect { |branch| branch =~ CURRENT_BRANCH }.sub(CURRENT_BRANCH, "")
    end

    def self.detached?
      stripped.any? { |branch| branch =~ NO_BRANCH }
    end

    private

      def self.list
        stripped.reject { |b| b =~ NO_BRANCH }
      end

      def self.stripped
        pipe.map(&:strip)
      end

      def self.pipe
        Pipe.new("git --no-pager branch --no-color")
      end

  end
end

module GitStatistics
  class Branches

    CURRENT_BRANCH = /\A\*\s/

    def self.all
      list.collect { |branch| branch.sub(CURRENT_BRANCH, "") }
    end

    def self.current
      return '(none)' if detached?
      list.detect { |branch| branch =~ CURRENT_BRANCH }.sub(CURRENT_BRANCH, "")
    end

    def self.detached?
      stripped.any? { |branch| branch =~ /no branch/i }
    end

    private

      def self.list
        stripped.reject { |b| b =~ /no branch/i }
      end

      def self.stripped
        pipe.map(&:strip)
      end

      def self.pipe
        Pipe.new("git --no-pager branch --no-color")
      end

  end
end

--- 
+++ 
@@ -2,6 +2,7 @@
   class Branches
 
     CURRENT_BRANCH = /\A\*\s/
+    NO_BRANCH = /no branch/i
 
     def self.all
       list.collect { |branch| branch.sub(CURRENT_BRANCH, "") }
@@ -13,13 +14,13 @@
     end
 
     def self.detached?
-      stripped.any? { |branch| branch =~ /no branch/i }
+      stripped.any? { |branch| branch =~ NO_BRANCH }
     end
 
     private
 
       def self.list
-        stripped.reject { |b| b =~ /no branch/i }
+        stripped.reject { |b| b =~ NO_BRANCH }
       end
 
       def self.stripped
Move duplicated regex into constant
