Class: Taskish::App

Inherits:
Object
  • Object
show all
Defined in:
lib/taskish/app.rb

Overview

Taskish::App - Taskish application.

USAGE

API:

Taskish::App.run(ARGV)

Command Line:

% taskish <command> <task file> [<task file N>]

SEE ALSO

<Taskish>

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ App

Returns a new instance of App.

Yields:

  • (_self)

Yield Parameters:

  • _self (Taskish::App)

    the object that the method was called on



24
25
26
27
28
# File 'lib/taskish/app.rb', line 24

def initialize
  @command  = nil
  @files    = nil
  yield self if block_given?
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



22
23
24
# File 'lib/taskish/app.rb', line 22

def command
  @command
end

#filesObject (readonly)

Returns the value of attribute files.



22
23
24
# File 'lib/taskish/app.rb', line 22

def files
  @files
end

Class Method Details

.run(args) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/taskish/app.rb', line 43

def self.run(args)
  Taskish::App.new do |app|
    app.args(args)
    return app.abort('no command specified') unless app.command

    case  app.command
    when  'help'
      puts app.usage
      return true
    when  'version'
      puts "Taskish v#{ Taskish::VERSION }"
      return true
    else
      return app.abort('no file specified') unless app.files
      Taskish.new do |taskish|
        app.files.each { |f| taskish.readlines(f) }
        case  app.command
        when  'debug'
          taskish.debug
        when  'done'
          puts "DONE\n~~~~"
          taskish.done.each { |task| puts task }
        when  'today', 'tomorrow', 'week'
          tasks = taskish.due( app.command.to_sym )
          if tasks.size > 0
            tasks.each { |task| puts task }
          end
        else
          return app.abort("unknown command: #{app.command}")
        end
      end
    end
  end
end

Instance Method Details

#abort(message = nil) ⇒ Object



30
31
32
33
34
# File 'lib/taskish/app.rb', line 30

def abort(message = nil)
  warn "ERROR: #{message}" if message
  warn self.usage
  false 
end

#args(args) ⇒ Object

Raises:

  • (ArgumentError)


36
37
38
39
40
41
# File 'lib/taskish/app.rb', line 36

def args(args)
  raise(ArgumentError, 'invalid argument(s)') if ( args.nil? || !args.kind_of?(Array) )
  @command  = args.shift
  @files    = args
  self
end

#usageObject



78
79
80
# File 'lib/taskish/app.rb', line 78

def usage
  "USAGE: taskish { debug | done | today | tomorrow | week } <file>"
end