class Kitnahua::Kitnahua
Attributes
projects[RW]
Public Class Methods
new()
click to toggle source
# File lib/kitnahua.rb, line 8 def initialize @db_yml_path = ENV['HOME'] + "/.kitnahua.yml" # Create file if does not exist. create_db_file if !File.exists?(@db_yml_path) load_projects end
Public Instance Methods
parse_and_execute_args(argv)
click to toggle source
# File lib/kitnahua.rb, line 17 def parse_and_execute_args(argv) if argv[0] == nil show_status elsif argv[0] == "--reset" reset_db_file elsif argv[0] == "--show" show_db_file elsif argv[0] == "--count" show_projects_count elsif argv[0] == "--create" create_project(argv[1]) elsif project = argv[0].to_s.strip end end
Private Instance Methods
create_db_file()
click to toggle source
# File lib/kitnahua.rb, line 69 def create_db_file everything = { "projects" => {} } File.open(@db_yml_path,'w') do |f| f.puts everything.to_yaml puts "Created db file #{@db_yml_path} " end end
create_project(name)
click to toggle source
# File lib/kitnahua.rb, line 37 def create_project(name) # Return if no name was passed. if name == nil puts "Please provide a project name!" return end # Return if project name is more than 25 chars. if name.length > 25 puts "Project name cannot be more than 25 chars!" return end # Return if project with passed name already exists if @projects[name] != nil puts "Project with that name already exists!" return end @projects[name] = [] write_projects_to_db puts "Created project '#{name}'." end
load_projects()
click to toggle source
# File lib/kitnahua.rb, line 63 def load_projects File.open(@db_yml_path,'r') do |f| @projects = YAML.load(f)["projects"] end end
reset_db_file()
click to toggle source
# File lib/kitnahua.rb, line 77 def reset_db_file File.delete(@db_yml_path) puts "Deleted db file #{@db_yml_path}" create_db_file end
show_db_file()
click to toggle source
# File lib/kitnahua.rb, line 83 def show_db_file File.open(@db_yml_path,'r') do |f| puts YAML.load(f).to_yaml end end
show_projects_count()
click to toggle source
# File lib/kitnahua.rb, line 89 def show_projects_count puts @projects.count end
show_status()
click to toggle source
# File lib/kitnahua.rb, line 100 def show_status puts "TODO: Show status summary of each prohect" end
write_projects_to_db()
click to toggle source
# File lib/kitnahua.rb, line 93 def write_projects_to_db everything = { "projects" => @projects } File::open(@db_yml_path,'w') do |f| f.write(everything.to_yaml) end end