<commit_before>module Rubdo
  class CLI
    def initialize
      @list = List.new
      @id = ARGV[1].to_i - 1 
    end

    def add
      @list.add ARGV[1] if ARGV[1]
      unless ARGV[1]
        tmp_file = '/tmp/new_task.txt'
        system("$EDITOR #{tmp_file}")
        if File.exists? tmp_file
          @list.add File.read(tmp_file).chomp  
          File.delete(tmp_file)
        else
          puts "aborted due to empty file"
        end
      end
    end

    def done
      @list.done @id
    end

    def remove
      @list.remove @id
    end

    def save
      @list.write
    end

    def list
      @list.items.each_with_index { |item, index| puts "#{index + 1}: #{item.description}" }
      puts "no tasks" if @list.items.empty?
    end

    def info
      puts @list.info @id
    end

    def completed
      @list.completed.each { |item| puts "#{item.description}, completed at: #{item.completed_at.strftime('%m.%d.%y - %H:%M')}" }
    end

    def edit
      tmp_file = '/tmp/todo_desc.txt'
      system("echo '#{@list.items[@id].description}' > #{tmp_file}")
      system("$EDITOR #{tmp_file}")
      @list.items[@id].description = File.read(tmp_file).chomp
      File.delete(tmp_file)
    end

    def remove
      @list.items.delete_at(@id)
    end

    def help
      puts <<-HELP
Commands for rubdo:
------------------     
add/a [task description] - Add a new task. If the description is empty, $EDITOR is opened
list/ls - Lists all tasks
completed - List all completed tasks
done/d [task id] - Complete a task
info [task id] - Gives info about the specific task
edit/e [task id] - Opens up $EDITOR to edit the task description
remove/rm [task id] - Deletes the specific task
help - Prints out this information
      HELP
    end

    alias_method :a, :add
    alias_method :ls, :list
    alias_method :d, :done
    alias_method :e, :edit
    alias_method :rm, :remove
  end
end
<commit_msg>Now using the tempfile library Fixed some of the feedback from the reddit-thread (http://www.reddit.com/r/ruby/comments/y0e23/my_first_real_ruby_project_give_my_some_feedback/)<commit_after>require 'tempfile'

module Rubdo
  class CLI
    def initialize
      @list = List.new
      @id = ARGV[1].to_i - 1 
    end

    def add
      @list.add ARGV[1] if ARGV[1]
      tmp_file = Tempfile.new('new_task')
      system("$EDITOR #{tmp_file.path}")
      unless File.read(tmp_file.path).empty?
        @list.add File.read(tmp_file).chomp  
        tmp_file.unlink
      else
        puts "aborted due to empty file"
      end
    end

    def done
      @list.done @id
    end

    def remove
      @list.remove @id
    end

    def save
      @list.write
    end

    def list
      @list.items.each_with_index { |item, index| puts "#{index + 1}: #{item.description}" }
      puts "no tasks" if @list.items.empty?
    end

    def info
      puts @list.info @id
    end

    def completed
      @list.completed.each { |item| puts "#{item.description}, completed at: #{item.completed_at.strftime('%m.%d.%y - %H:%M')}" }
    end

    def edit
      tmp_file = Tempfile.new('todo_desc.txt')
      File.open(tmp_file.path, 'w') { |f| f.write(@list.items[@id].description) }
      system("$EDITOR #{tmp_file.path}")
      @list.items[@id].description = File.read(tmp_file).chomp
      Tempfile.delete(tmp_file)
    end

    def remove
      @list.items.delete_at @id
    end

    def help
      puts <<-HELP
Commands for rubdo:
------------------     
add/a [task description] - Add a new task. If the description is empty, $EDITOR is opened
list/ls - Lists all tasks
completed - List all completed tasks
done/d [task id] - Complete a task
info [task id] - Gives info about the specific task
edit/e [task id] - Opens up $EDITOR to edit the task description
remove/rm [task id] - Deletes the specific task
help - Prints out this information
      HELP
    end

    alias_method :a, :add
    alias_method :ls, :list
    alias_method :d, :done
    alias_method :e, :edit
    alias_method :rm, :remove
  end
end

{'fraction_non_alphanumeric': 0.12045793927327028, 'fraction_numerical': 0.003484320557491289, 'mean_word_length': 2.2969647251845777, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1253906', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1339, 'n_words': 395}