Sha256: e97d497dd0ecae9b763e32b7d4a73f8522623407ae47721c2869c6d74e4a5bfb

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

module PairSee
  class LogLine
    require 'time'
    attr_reader :line

    def initialize(line)
      @line = line
    end

    def authored_by?(*people)
      people.empty? ? false : people.all? do |person|
        /(^|\s+|\W)#{person}(\s+|$|\W)/i =~ line
      end
    end

    def contains_card?(card_prefix)
      line.match(card_prefix)
    end

    def contains_card_name?(card_name)
      git_regex = /#{card_name}[\]\s\[,:]/
      git_matcher = line.match(git_regex)
      !git_matcher.nil?
    end

    def card_name(card_prefix)
      regex = /(#{card_prefix}\d+)/
      matcher = line.match(regex)
      matcher.nil? ? nil : (line.match regex)[1]
    end

    def card_number(card_prefix)
      card_num = card_name(card_prefix)
      card_num ? card_num.gsub(card_prefix, '') : nil
    end

    def merge_commit?
      line.match('Merge remote-tracking branch') || line.match('Merge branch')
    end

    def date
      regex = /(\d{4}-\d{2}-\d{2})/
      matcher = line.match(regex)
      part_to_parse = matcher.nil? ? '' : (line.match regex)[1]
      Date.parse(part_to_parse)
    end

    def not_by_pair?(devs)
      devs.any? { |dev| authored_by?(dev) || merge_commit? }
    end

    def to_s
      line
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pair_see-0.1.4 lib/pair_see/log_line.rb
pair_see-0.1.3 lib/pair_see/log_line.rb
pair_see-0.1.2 lib/pair_see/log_line.rb
pair_see-0.1.1 lib/pair_see/log_line.rb