Module: FindSharedLines
- Defined in:
- lib/find_shared_lines.rb,
lib/find_shared_lines/version.rb,
lib/find_shared_lines/command_line_interface.rb
Defined Under Namespace
Modules: CommandLineInterface
Classes: Error
Constant Summary
collapse
- VERSION =
'0.1.0'
Class Method Summary
collapse
Class Method Details
.exclude_shared_lines(files) ⇒ Object
23
24
25
|
# File 'lib/find_shared_lines.rb', line 23
def self.exclude_shared_lines(files)
reduce(files) { |first_file, file| first_file - file }
end
|
.join(files) ⇒ Object
31
32
33
|
# File 'lib/find_shared_lines.rb', line 31
def self.join(files)
reduce(files) { |first_file, file| first_file | file }
end
|
.read_file_into_set(file) ⇒ Object
13
14
15
|
# File 'lib/find_shared_lines.rb', line 13
def self.read_file_into_set(file)
Set.new(read_lines_from(file))
end
|
.read_lines_from(file) ⇒ Object
9
10
11
|
# File 'lib/find_shared_lines.rb', line 9
def self.read_lines_from(file)
File.open(file).readlines.map(&:chomp)
end
|
.reduce(files) ⇒ Object
17
18
19
20
21
|
# File 'lib/find_shared_lines.rb', line 17
def self.reduce(files)
first_file, *rest = files
first_set = read_file_into_set(first_file)
rest.reduce(first_set) { |acc, file| yield acc, read_file_into_set(file) }
end
|
.shared_lines(files) ⇒ Object
27
28
29
|
# File 'lib/find_shared_lines.rb', line 27
def self.shared_lines(files)
reduce(files) { |first_file, file| first_file & file }
end
|