module Ptf::Commands::Task::Create
Public Class Methods
create(t, g, d, e)
click to toggle source
# File lib/ptf/commands/task/create.rb, line 24 def create(t, g, d, e) title = t group = g due_date = d estimate = e # Select a group for the task if group.nil? group = Ptf::Group.default_group else if Ptf::Group.group_exist? group group = Ptf::Group.get_group group else return "Group #{p} does not exist. Create it with ptf group add GROUP ABBREVIATION" end end # Verify the due date if !due_date.nil? due_date = Ptf::Date.create_datetime_from_str(due_date) if due_date.nil? return "Improperly formatted due date '#{d}' given." end end id = new_id_number info_file = Ptf::MetadataFile.create_from_input(title, group, due_date, estimate, id) task_info_hash = generate_hash info_file.file_string # Append hash to the file info_file.add_content(:hash, task_info_hash) data_file = Ptf::DataFile.new(info_file) info_file.write_to_file data_file.write_to_file return "Task #{info_file.id} created successfully." end
generate_hash(file_contents)
click to toggle source
# File lib/ptf/commands/task/create.rb, line 9 def generate_hash(file_contents) Digest::SHA1.hexdigest file_contents end
new_id_number()
click to toggle source
# File lib/ptf/commands/task/create.rb, line 13 def new_id_number id_file_path = Ptf::FileSystem.id_counter_file next_id = File.read(id_file_path).to_i id_file = File.new(id_file_path, "w") id_file.write("#{next_id+1}") id_file.close next_id end