Class: PairSee::LogLine

Inherits:
Object
  • Object
show all
Defined in:
lib/pair_see/log_line.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ LogLine

Returns a new instance of LogLine.



6
7
8
# File 'lib/pair_see/log_line.rb', line 6

def initialize(line)
  @line = line
end

Instance Attribute Details

#lineObject (readonly)

Returns the value of attribute line.



4
5
6
# File 'lib/pair_see/log_line.rb', line 4

def line
  @line
end

Instance Method Details

#authored_by?(*people) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
# File 'lib/pair_see/log_line.rb', line 10

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

#card_name(card_prefix) ⇒ Object



26
27
28
29
30
# File 'lib/pair_see/log_line.rb', line 26

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

#card_number(card_prefix) ⇒ Object



32
33
34
35
# File 'lib/pair_see/log_line.rb', line 32

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

#contains_card?(card_prefix) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/pair_see/log_line.rb', line 16

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

#contains_card_name?(card_name) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
# File 'lib/pair_see/log_line.rb', line 20

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

#dateObject



41
42
43
44
45
46
# File 'lib/pair_see/log_line.rb', line 41

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

#merge_commit?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/pair_see/log_line.rb', line 37

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

#not_by_pair?(devs) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/pair_see/log_line.rb', line 48

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

#to_sObject



52
53
54
# File 'lib/pair_see/log_line.rb', line 52

def to_s
  line
end