habittracker 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e8904683ceb865985ce7764dc0cfe9f28936248e
4
+ data.tar.gz: 605fbbd11e9c617c3da15644e7428a8d540da684
5
+ SHA512:
6
+ metadata.gz: 0e22065348ba210ef8ab61579da24742d7c06de6565f70b498240543b8b5facbc5034fc411f92ebea8d878df06689bd198b41b08c92441523254e83074cf3b13
7
+ data.tar.gz: d0d40746e75a3c164e9d4df1d04ccffee0cd9c3fba74cf37939b9eae4d09b9792977c210132bae1a27f4a0aad60665f77388b0caef3f2be1ec8ac0a8d9995908
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.13.7
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in habittracker.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Calo, Ignazio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,98 @@
1
+ Habit Tracker
2
+ ============
3
+
4
+ **This:**
5
+
6
+ ![](docs/paper_tracking.jpg)
7
+
8
+ **for him:**
9
+
10
+ ![](docs/linux_geek.jpg)
11
+
12
+ ```bash
13
+ >./ht add "Play Tennis" "Study German" "Do 20 pushups" "Miracle morning"
14
+ >./ht do
15
+ What did you do?
16
+ 1. Play Tennis
17
+ 2. Study German
18
+ 3. Do 20 pushup
19
+ 4. Miracle morning
20
+ ? 1
21
+ When did you "Play Tennis" the last time?
22
+ 1. Today
23
+ 2. Yesteday
24
+ 3. Fri 13
25
+ 4. Thu 12
26
+ 5. Wed 11
27
+ 6. Tue 10
28
+ ? 1
29
+
30
+ ./ht report
31
+
32
+ +-----+-------------+--------------+--------------+-----------------+
33
+ | January |
34
+ +-----+-------------+--------------+--------------+-----------------+
35
+ | Day | Play Tennis | Study German | Do 20 pushup | Miracle morning |
36
+ +-----+-------------+--------------+--------------+-----------------+
37
+ | 01 | | | | X |
38
+ | 02 | | | | X |
39
+ | 03 | | | | X |
40
+ | 04 | | | X | X |
41
+ | 05 | | | | X |
42
+ | 06 | | | X | X |
43
+ | 07 | X | | | X |
44
+ | 08 | X | X | X | X |
45
+ | 09 | | | X | X |
46
+ | 10 | X | | X | X |
47
+ | 11 | | X | | X |
48
+ | 12 | | | | X |
49
+ | 13 | | X | X | X |
50
+ | 14 | X | | X | X |
51
+ | 15 | | | | X |
52
+ | 16 | | X | X | X |
53
+ | 17 | | | | X |
54
+ | 18 | | | X | X |
55
+ | 19 | | X | | X |
56
+ | 20 | | | | X |
57
+ | 21 | | X | X | X |
58
+ | 22 | | | | X |
59
+ | 23 | | X | | X |
60
+ | 24 | X | | | X |
61
+ | 25 | | | | X |
62
+ | 26 | | | | X |
63
+ | 27 | | X | | X |
64
+ | 28 | X | | | X |
65
+ | 29 | | | | X |
66
+ | 30 | | | | X |
67
+ | 31 | | | | X |
68
+ +-----+-------------+--------------+--------------+-----------------+
69
+ ```
70
+ NAME:
71
+
72
+ ht
73
+
74
+ DESCRIPTION:
75
+
76
+ Track your monthly habits
77
+
78
+ COMMANDS:
79
+
80
+ add Add one or more habits to the list
81
+ do Record your activities
82
+ habits Print the list of current habits
83
+ help Display global or [command] help documentation
84
+ report Print the current month's activities
85
+ rm Remove one or more habits from the list
86
+
87
+ GLOBAL OPTIONS:
88
+
89
+ -h, --help
90
+ Display help documentation
91
+
92
+ -v, --version
93
+ Display version information
94
+
95
+ -t, --trace
96
+ Display backtrace when an error occurs
97
+
98
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
Binary file
Binary file
data/exe/ht ADDED
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env ruby
2
+ require "habittracker"
3
+
4
+ program :name, 'ht'
5
+ program :version, '0.0.1'
6
+ program :description, 'Track your monthly habits'
7
+
8
+ command :add do |c|
9
+ c.syntax = 'ht add <habits>'
10
+ c.summary = 'Add one or more habits to the list'
11
+ c.description = 'Add one or more habits to the list'
12
+ c.example 'description', 'ht add_habit "Learn math" "Play piano"'
13
+ c.action do |args, _options|
14
+ archive = Archive.new
15
+ args.each do |habit|
16
+ archive.add_habit(habit)
17
+ end
18
+ end
19
+ end
20
+
21
+ command :rm do |c|
22
+ c.syntax = 'ht rm <options>'
23
+ c.summary = 'Remove one or more habits from the list'
24
+ c.description = 'Remove one or more habits from the list'
25
+ c.example 'description', 'ht rm_habit "Learn math" "Play piano"'
26
+ c.action do |args, _options|
27
+ archive = Archive.new
28
+ args.each do |habit|
29
+ archive.rm_habit(habit)
30
+ end
31
+ end
32
+ end
33
+
34
+ command :habits do |c|
35
+ c.syntax = 'ht habits'
36
+ c.summary = 'Print the list of current habits'
37
+ c.description = 'Print the list of current habits'
38
+ c.example 'description', 'ht habits'
39
+ c.action do |_args, _options|
40
+ Archive.new.print_habits
41
+ end
42
+ end
43
+
44
+ command :report do |c|
45
+ c.syntax = 'ht report'
46
+ c.summary = "Print the current month's activities"
47
+ c.description = "Print the current month's activities"
48
+ c.example 'description', 'ht report'
49
+ c.action do |_args, _options|
50
+ from = Date.new(Time.now.year, Time.now.month, 1)
51
+ to = Date.new(Time.now.year, Time.now.month, -1)
52
+ Archive.new.print_status(from, to)
53
+ end
54
+ end
55
+
56
+ command :do do |c|
57
+ c.syntax = 'ht do'
58
+ c.summary = 'Record your activities'
59
+ c.description = 'Record your activities'
60
+ c.example 'description', 'ht do'
61
+ c.action do |_args, _options|
62
+ archive = Archive.new
63
+
64
+ habit = choose('What did you do?', *archive.habits)
65
+ dates = (0..5).map { |i| (Date.today - i) }
66
+ options = dates.map { |date| date.strftime('%a %d') }
67
+
68
+ options[0] = 'Today'
69
+ options[1] = 'Yesteday'
70
+
71
+ choice = choose("When did you \"#{habit}\" the last time?", *options)
72
+ index = options.find_index(choice)
73
+
74
+ selected_date = dates[index]
75
+
76
+ archive.save(habit, selected_date)
77
+ end
78
+ end
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'habittracker/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "habittracker"
8
+ spec.version = Habittracker::VERSION
9
+ spec.authors = ["Ignazio Calò"]
10
+ spec.email = ["ignazioc@gmail.com"]
11
+
12
+ spec.summary = "This is a monthly tracker for geeks."
13
+ spec.description = "This is a monthly tracker for geeks."
14
+ spec.homepage = "https://github.com/ignazioc/HabitTracker"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.required_ruby_version = '~> 2.3'
30
+
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.13"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "minitest", "~> 5.0"
38
+
39
+ spec.add_dependency 'commander'
40
+ spec.add_dependency 'terminal-table'
41
+ end
@@ -0,0 +1,6 @@
1
+ require "habittracker/version"
2
+ require "habittracker/archive"
3
+ require 'yaml'
4
+ require 'date'
5
+ require 'terminal-table'
6
+ require 'commander/import'
@@ -0,0 +1,97 @@
1
+ class Archive
2
+
3
+ def initialize
4
+ @db_file = File.join(ENV['HOME'], '/.ht')
5
+ load_archive
6
+ end
7
+
8
+ def add_habit(habit)
9
+ from = Date.new(Time.now.year, 1, 1)
10
+ to = Date.new(Time.now.year, 12, 31)
11
+
12
+ @archive[habit] = from.upto(to).each_with_object({}) do |day, mem|
13
+ mem[date_to_key(day)] = false
14
+ mem
15
+ end
16
+ store
17
+ load_archive
18
+ end
19
+
20
+ def rm_habit(habit)
21
+ @archive.delete(habit)
22
+ store
23
+ load_archive
24
+ end
25
+
26
+ def habits
27
+ @archive.keys
28
+ end
29
+
30
+ def print_habits
31
+ habits.each { |h| puts h }
32
+ end
33
+
34
+ def print_status(from, to)
35
+ keys_to_print = from.upto(to).map { |day| date_to_key(day) }
36
+
37
+ rows = keys_to_print.map do |day|
38
+ row = [short_key(day)]
39
+
40
+ habits.each do |habit|
41
+ hits = @archive[habit]
42
+ row << row_item(hits[day])
43
+ end
44
+ row
45
+ end
46
+
47
+ header = habits.unshift('Day')
48
+ puts Terminal::Table.new title: Time.now.strftime('%B'), headings: header, rows: rows
49
+ end
50
+
51
+ def save(habit, date)
52
+ calendar = @archive[habit]
53
+ return if calendar.nil?
54
+
55
+ key = date_to_key(date)
56
+ calendar[key] = true
57
+ store
58
+ load_archive
59
+ end
60
+
61
+ #-- Private Methods
62
+
63
+ private def load_archive
64
+ unless File.exist? @db_file
65
+ File.open(@db_file, 'w') do |file|
66
+ file.write({}.to_yaml)
67
+ end
68
+ end
69
+ @archive = YAML.load_file(@db_file)
70
+ end
71
+
72
+ private def store
73
+ File.open(@db_file, 'w') do |file|
74
+ file.write(@archive.to_yaml)
75
+ end
76
+ end
77
+
78
+ private def date_to_key(date)
79
+ date.strftime('%Y.%m.%d')
80
+ end
81
+
82
+ private def key_to_date(key)
83
+ Date.strptime(key, '%Y.%m.%d')
84
+ rescue
85
+ return nil
86
+ end
87
+
88
+ private def short_key(key)
89
+ key[-2..-1]
90
+ end
91
+
92
+ private def row_item(value)
93
+ value ? { value: 'X', alignment: :center } : { value: '', alignment: :center }
94
+ end
95
+
96
+
97
+ end
@@ -0,0 +1,3 @@
1
+ module Habittracker
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: habittracker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ignazio Calò
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-01-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: commander
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: terminal-table
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: This is a monthly tracker for geeks.
84
+ email:
85
+ - ignazioc@gmail.com
86
+ executables:
87
+ - ht
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - docs/linux_geek.jpg
99
+ - docs/paper_tracking.jpg
100
+ - exe/ht
101
+ - habittracker.gemspec
102
+ - lib/habittracker.rb
103
+ - lib/habittracker/archive.rb
104
+ - lib/habittracker/version.rb
105
+ homepage: https://github.com/ignazioc/HabitTracker
106
+ licenses:
107
+ - MIT
108
+ metadata:
109
+ allowed_push_host: https://rubygems.org
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '2.3'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.6.8
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: This is a monthly tracker for geeks.
130
+ test_files: []