Sha256: f60eaa3eb9158bb820b8b98329e2b934bb1f15fb82f33229179ab8a0af89108f

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

module PairSee
  class LogLine
    require 'time'
    attr_reader :line

    def initialize(line)
      @line = line
    end

    def authored_by?(*people)
      return false if people.empty?
      people.map {|person|
        contains_any_of?(person.names)
      }.all?
    end

    def contains_any_of?(names)
      names.any? {|name| line_contains_name(name)}
    end

    def line_contains_name(name)
      /(^|\s+|\W)#{name}(\s+|$|\W)/i =~ line
    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_prefixes)
      card_prefixes.each {|cp|
        regex = /(#{cp}\d+)/
        matcher = line.match(regex)
        if (!matcher.nil?)
          return (line.match regex)[1]
        end
      }
      return nil
    end

    def card_number(card_prefixes)
      card_prefixes.each {|cp|
        card_num = card_name([cp])
        if (card_num)
          return card_num.gsub(cp, '')
        end
      }
      return 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 by_any?(devs)
      if devs.size == 0
        return false
      end
      devs.any? {|dev| authored_by?(dev)}
    end

    def to_s
      line
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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