class Brag

Constants

DEFAULT_FILE

Public Class Methods

add_to_file(file, text) click to toggle source
# File lib/brag.rb, line 19
def self.add_to_file(file, text)
    open(file, 'a+') do |file|
      file.puts "#{Time.now.strftime("%m-%d-%y %H:%M")} - #{text}"
    end
end
help_page() click to toggle source
# File lib/brag.rb, line 40
    def self.help_page
        "Usage: brag [ACCOMPLISHMENT]
Keep a list of accomplishments.\n
Pass in 'sheet' (ie: `brag sheet`)
to list your accomplishments.\n
Examples:
brag finished the mvp
brag sheet\n"
    end
no_brags?(file) click to toggle source
# File lib/brag.rb, line 34
def self.no_brags?(file)
    # if the file doesn't exist
    # if the file is empty
   !File.exists?(file) || File.zero?(file)
end
parse(args) click to toggle source
# File lib/brag.rb, line 6
def self.parse(args)
    if args.empty?
        puts help_page
    elsif args[0] == "sheet"
        read_file(DEFAULT_FILE)
        # print the list
    else
        brag_text = args.join(" ")
        add_to_file(DEFAULT_FILE, brag_text)
        puts "added '#{brag_text}' to your brag sheet"
    end
end
read_file(file) click to toggle source
# File lib/brag.rb, line 25
def self.read_file(file)
    return puts "no brags yet :(" if no_brags?(file)

    puts "here's your brags"
    open(file, 'a+').each do |line|
        print "#{line}"
    end
end