Class: GeneratePairs

Inherits:
Object
  • Object
show all
Defined in:
lib/makers_toolbelt/generate_pairs.rb

Constant Summary collapse

FILE_EXTENSION =
'pairs'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ GeneratePairs

Returns a new instance of GeneratePairs.


13
14
15
# File 'lib/makers_toolbelt/generate_pairs.rb', line 13

def initialize(options = {})
  @source = options[:source]
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.


7
8
9
# File 'lib/makers_toolbelt/generate_pairs.rb', line 7

def source
  @source
end

Class Method Details

.load_names(file_path) ⇒ Object


9
10
11
# File 'lib/makers_toolbelt/generate_pairs.rb', line 9

def self.load_names(file_path)
  File.readlines(file_path).map(&:strip)
end

Instance Method Details

#pathObject


25
26
27
# File 'lib/makers_toolbelt/generate_pairs.rb', line 25

def path
  File.join(source_directory, filename)
end

#runObject


17
18
19
20
21
22
23
# File 'lib/makers_toolbelt/generate_pairs.rb', line 17

def run
  names = GeneratePairs.load_names(source)
  File.open(path, 'w') do |file|
    puts "Pair assignments created in file #{path}"
    file.write names.one_factorize.shuffle.to_json
  end
end