Class: XRT::Command::LCS

Inherits:
Object
  • Object
show all
Defined in:
lib/xrt/command/lcs.rb

Instance Method Summary collapse

Instance Method Details

#collect(*files) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/xrt/command/lcs.rb', line 16

def collect(*files)
  products = statements(files.shift)
  while files.length > 0
    products = products.product(statements(files.shift))
  end

  products.select{|pairs|
    pairs.flatten.uniq.length == 1
  }.map{|pairs| pairs.first }.sort_by{|s| s.length}
end

#execute(*files) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/xrt/command/lcs.rb', line 6

def execute(*files)
  lcs = collect(*files)
  if lcs.length > 0
    puts lcs.join("\n---\n")
    true
  else
    false
  end
end

#statements(file) ⇒ Object



27
28
29
# File 'lib/xrt/command/lcs.rb', line 27

def statements(file)
  XRT::Parser.new(open(file).read).document.find_blocks.map{|s| s.auto_indent }
end