Class: FixTSVConflict::Conflict

Inherits:
Object
  • Object
show all
Defined in:
lib/fix_tsv_conflict/conflict.rb

Constant Summary collapse

ID_REGEXP =
/\A[0-9]+\t/
NL_REGEXP =
/\A\n/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(left, lbranch, right, rbranch) ⇒ Conflict



5
6
7
8
9
10
# File 'lib/fix_tsv_conflict/conflict.rb', line 5

def initialize(left, lbranch, right, rbranch)
  @left = left
  @lbranch = lbranch
  @right = right
  @rbranch = rbranch
end

Instance Attribute Details

#lbranchObject (readonly)

Returns the value of attribute lbranch.



3
4
5
# File 'lib/fix_tsv_conflict/conflict.rb', line 3

def lbranch
  @lbranch
end

#leftObject (readonly)

Returns the value of attribute left.



3
4
5
# File 'lib/fix_tsv_conflict/conflict.rb', line 3

def left
  @left
end

#rbranchObject (readonly)

Returns the value of attribute rbranch.



3
4
5
# File 'lib/fix_tsv_conflict/conflict.rb', line 3

def rbranch
  @rbranch
end

#rightObject (readonly)

Returns the value of attribute right.



3
4
5
# File 'lib/fix_tsv_conflict/conflict.rb', line 3

def right
  @right
end

Instance Method Details

#to_aObject



20
21
22
23
24
25
26
27
28
# File 'lib/fix_tsv_conflict/conflict.rb', line 20

def to_a
  result = []
  result << "#{LEFT} #{lbranch}\n"
  result += left
  result << "#{SEP}\n"
  result += right
  result << "#{RIGHT} #{rbranch}\n"
  result
end

#valid?Boolean



15
16
17
18
# File 'lib/fix_tsv_conflict/conflict.rb', line 15

def valid?
  left.all? { |line| ID_REGEXP =~ line || NL_REGEXP =~ line} &&
    right.all? { |line| ID_REGEXP =~ line || NL_REGEXP =~ line }
end