class CrudeMutant::LinePermuter
Public Class Methods
new(file_contents)
click to toggle source
# File lib/crude_mutant/line_permuter.rb, line 5 def initialize(file_contents) @file_contents = file_contents end
Public Instance Methods
line(line_number)
click to toggle source
# File lib/crude_mutant/line_permuter.rb, line 26 def line(line_number) contents_as_array.fetch(line_number) end
number_of_permutations()
click to toggle source
# File lib/crude_mutant/line_permuter.rb, line 9 def number_of_permutations @number_of_permutations ||= @file_contents.split("\n").size end
take(permutation_number)
click to toggle source
# File lib/crude_mutant/line_permuter.rb, line 13 def take(permutation_number) if permutation_number < 0 raise ArgumentError, 'permutation_number must be 0 or more' end if permutation_number > number_of_permutations - 1 raise ArgumentError, 'permutation_number must be less than number_of_permutations - 1' end (contents_as_array.slice(0, permutation_number) + contents_as_array.slice(permutation_number + 1, number_of_permutations)).join("\n") end
Private Instance Methods
contents_as_array()
click to toggle source
# File lib/crude_mutant/line_permuter.rb, line 32 def contents_as_array @contents_as_array ||= @file_contents.split("\n") end