Class: Taskish::App
- Inherits:
-
Object
- Object
- Taskish::App
- Defined in:
- lib/taskish/app.rb
Overview
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
Class Method Summary collapse
Instance Method Summary collapse
- #abort(message = nil) ⇒ Object
- #args(args) ⇒ Object
-
#initialize {|_self| ... } ⇒ App
constructor
A new instance of App.
- #usage ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ App
Returns a new instance of App.
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
#command ⇒ Object (readonly)
Returns the value of attribute command.
22 23 24 |
# File 'lib/taskish/app.rb', line 22 def command @command end |
#files ⇒ Object (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( = nil) warn "ERROR: #{}" if warn self.usage false end |
#args(args) ⇒ Object
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 |
#usage ⇒ Object
78 79 80 |
# File 'lib/taskish/app.rb', line 78 def usage "USAGE: taskish { debug | done | today | tomorrow | week } <file>" end |