dataset.rb #4

  • //
  • guest/
  • jen_bottom/
  • scripts/
  • git/
  • dataset.rb
  • View
  • Commits
  • Open Download .zip Download (2 KB)
#This script allows the user to specify how many files they would like to include in their Git repo.
#It also allows them to specify how many insertions and deletions they would like.
require 'git'
class Dataset
require 'git'
  #Initialize variables to hold data entered by the user
  def initialize (repo, files, inserts, deletes, message="Commits to a test data set")
    @repo = repo
    @files = files
    @inserts = inserts
    @deletes = deletes
@message = message  
end

def createRepo(repo)
Dir.chdir repo
Dir.mkdir "testrepo"
Dir.chdir "testrepo"
#Initialize this as a git repo
$g = Git.init
       end

def createFiles(files)
puts files.inspect
  i = 1
while i <= files.to_i
  myFile = i.to_s
puts myFile.inspect  
#Add the file and dump in some random content
File.open(myFile, "wb") do |f2|
  f2.puts rand
  $g.add                                   # git add -- "."
puts i.inspect
i += 1
  end
  $g.commit(@message)
end  
end
def insertData(inserts)
  i = 1
  while i <= inserts.to_i
    #Open the file and ad some content
    myFile = i.to_s
puts myFile.inspect
File.open(myFile, "wb") do |f2|
      f2.puts "Hello, world."
    $g.add                                   # git add -- "."
puts i.inspect    
i += 1
  end
$g.commit(@message)
        
end
   end 
def deleteData(deletes)
i = 1
while i <= deletes.to_i
  myFile = i.to_s
puts myFile.inspect  
File.open(myFile, "wb") do |f2|
File.foreach(myFile).with_index do |line,line_number|
     f2.puts line if line_number.even?  # <== line numbers start at 0
  end
$g.add                                   # git add -- "."
puts i.inspect      
i += 1
end
$g.commit(@message)
end
end
#End class
end
def main()
  #Ask the user where they would like the Git repo to be created
  puts "Specify the location for your Git repo"
  userRepo = gets.chomp
  puts "Please enter the number of files required"
  userFiles = gets.chomp
  puts "Please enter the number of insertions"
  userInserts = gets.chomp
  puts "Please enter the number of deletions"
  userDeletes = gets.chomp
  #Create an instance of the class
  dataset = Dataset.new(userRepo, userFiles, userInserts, userDeletes)
  dataset.createRepo(userRepo)
  dataset.createFiles(userFiles)
  dataset.insertData(userInserts)
  dataset.deleteData(userDeletes)
end

#run main
main()

# Change User Description Committed
#4 25967 Jen Bottom copy up of dataset.rb
#3 25966 Jen Bottom Copy up from dev
#2 25965 Jen Bottom Adding some more content to files created with dataset.rb
#1 25962 Jen Bottom Copy up from dev to main