Sha256: a8c42457c96bd18497d820465ca206d963d60ac99d41af9e7699285ca47a65f9

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

require 'time'
class LogLine
  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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pair_see-0.1.0 lib/pair_see/log_line.rb