<commit_before>=begin rdoc

= UTILITIES.RB

*Author*::      <NAME> <<EMAIL>>
*Since*::       2013-02-10
*Copyright*::   (c) 2013 Tamara Temple Web Development
*License*::     MIT
  
=end

require 'methadone'

class Rsyncbackup
  
  def build_command
    
    cmd = []
    cmd << options[:rsync_cmd]
    cmd << '--verbose --progress --itemize-changes' if logger.info?
    cmd << '--archive'             if options[:archive]
    cmd << '--one-file-system'     if options[:one_file_system]
    cmd << '--hard-links'          if options[:hard_links]
    cmd << '--human-readable'      if options[:human_readable]
    cmd << '--inplace'             if options[:inplace]
    cmd << '--numeric-ids'         if options[:numeric_ids]
    cmd << '--delete'              if options[:delete]
    cmd << "--exclude-file #{options[:exclusions]}" if File.exist?(options[:exclusions])
    cmd << "--link-dest #{options[:link_dest]}" if options[:link_dest] || last_full_backup
    cmd << options[:source]
    cmd << "#{options[:target]}/.incomplete"
    
    cmd.join(' ').tap{|t| debug "Command: #{t}" }
    
  end
    
  def last_full_backup
    
    lastfull = "#{options[:target]}/.lastfull"
    if File.exist?(lastfull)
      options[:link_dest] = IO.readlines(lastfull).first.chomp
    end
    return false if options[:link_dest].nil?
    !options[:link_dest].empty?

  end
  
  def backup_dir_name
    Date.new.strftime("%FT%H-%M-%S")
  end

  def rsync_executable
    rsync = `which rsync`.chomp
    raise "No rsync executable. Are you sure it's installed?" if rsync.empty?
    rsync
  end


end<commit_msg>add assertion to strip_trailing_separator_if_any to make sure parameter s is a String<commit_after>=begin rdoc

= UTILITIES.RB

*Author*::      Tamara Temple <<EMAIL>>
*Since*::       2013-02-10
*Copyright*::   (c) 2013 Tamara Temple Web Development
*License*::     MIT
  
=end

require 'methadone'

class Rsyncbackup
  
  # returns the command string to execute with all parameters set
  def build_command
    
    cmd = []
    cmd << options[:rsync_cmd]
    cmd << '--verbose --progress --itemize-changes' if logger.info?
    cmd << '--archive'             if options[:archive]
    cmd << '--one-file-system'     if options[:one_file_system]
    cmd << '--hard-links'          if options[:hard_links]
    cmd << '--human-readable'      if options[:human_readable]
    cmd << '--inplace'             if options[:inplace]
    cmd << '--numeric-ids'         if options[:numeric_ids]
    cmd << '--delete'              if options[:delete]
    cmd << "--exclude-file #{options[:exclusions]}" if File.exist?(options[:exclusions])
    cmd << "--link-dest #{options[:link_dest]}" if options[:link_dest]
    cmd << options[:source]
    cmd << "#{options[:target]}/.incomplete"
    
    cmd.join(' ').tap{|t| debug "Command: #{t}" }
    
  end
    
  # returns the directory name of the last full backup
  # returns nil otherwise
  def last_full_backup
    
    lastfull = "#{options[:target]}/.lastfull"
    if File.exist?(lastfull)
      last_full_directory = IO.readlines(lastfull).first.chomp
    else
      nil
    end

  end
  
  # returns the directory name for the current backup
  # directory name consists of a time format: YYYY-MM-DDTHH-MM-SS
  def backup_dir_name
    Date.new.strftime("%FT%H-%M-%S")
  end

  # returns the path to the rsync executable
  # If none found, raises an Exception
  def rsync_executable
    rsync = `which rsync`.chomp
    raise "No rsync executable. Are you sure it\'s installed?" if rsync.empty?
    rsync
  end

  # Strip the trailing directory separator from the rsync
  # source or target.
  #
  # *s*:: string to strip
  def strip_trailing_separator_if_any(s)
    raise "not a String" unless s.is_a?(String)
    s = s.gsub(%r{/$},'')
  end

end
{'fraction_non_alphanumeric': 0.14047619047619048, 'fraction_numerical': 0.006349206349206349, 'mean_word_length': 2.736166007905138, 'pattern_counts': {'":': 0, '<': 60, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5803965', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1226, 'n_words': 324}