habittracker 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e8904683ceb865985ce7764dc0cfe9f28936248e
4
- data.tar.gz: 605fbbd11e9c617c3da15644e7428a8d540da684
3
+ metadata.gz: 546be2a9bca1b4182ae87a703a29caf75a1ea377
4
+ data.tar.gz: fe5bdbb348ba33c18c79cec0ba91205e0508f866
5
5
  SHA512:
6
- metadata.gz: 0e22065348ba210ef8ab61579da24742d7c06de6565f70b498240543b8b5facbc5034fc411f92ebea8d878df06689bd198b41b08c92441523254e83074cf3b13
7
- data.tar.gz: d0d40746e75a3c164e9d4df1d04ccffee0cd9c3fba74cf37939b9eae4d09b9792977c210132bae1a27f4a0aad60665f77388b0caef3f2be1ec8ac0a8d9995908
6
+ metadata.gz: '09321ebc8e1228ccf42595a2c7633b48cb17dcd174aec5c91489526fc0c2858a8e7f8ed4bd65f45255ecdb0420c0f936b93d945a01d56988dcaaef198376fc98'
7
+ data.tar.gz: 4a83603c97e9a48fbcdb748a1c4fbd9d420f7a7e1069d45e651a5146ad401710cde285dabba0b0d4924e8c04d58dac66ed2c34de0ac96332f4f6a6b147720e02
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in habittracker.gemspec
4
- gemspec
4
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- habittracker (0.1.0)
4
+ habittracker (0.1.1)
5
5
  commander
6
6
  terminal-table
7
7
 
data/README.md CHANGED
@@ -9,6 +9,11 @@ Habit Tracker
9
9
 
10
10
  ![](docs/linux_geek.jpg)
11
11
 
12
+ ## How to install
13
+ gem install habittracker
14
+
15
+ ## How to use it
16
+
12
17
  ```bash
13
18
  >./ht add "Play Tennis" "Study German" "Do 20 pushups" "Miracle morning"
14
19
  >./ht do
data/Rakefile CHANGED
@@ -1,10 +1,10 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
3
 
4
4
  Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
7
  t.test_files = FileList['test/**/*_test.rb']
8
8
  end
9
9
 
10
- task :default => :test
10
+ task default: :test
data/exe/ht CHANGED
@@ -1,19 +1,23 @@
1
1
  #!/usr/bin/env ruby
2
- require "habittracker"
2
+ require 'habittracker'
3
3
 
4
4
  program :name, 'ht'
5
- program :version, '0.0.1'
5
+ program :version, '0.1.1'
6
6
  program :description, 'Track your monthly habits'
7
+ default_command :today
7
8
 
8
9
  command :add do |c|
9
- c.syntax = 'ht add <habits>'
10
+ c.syntax = 'ht add <habits> [--schedule 1,2,4]'
10
11
  c.summary = 'Add one or more habits to the list'
11
12
  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|
13
+ c.example 'Add a "Learn math" habit for Monday, Wednesday and Friday ', 'ht add_habit "Learn math" --schedule 1,3,5'
14
+ c.option '--schedule STRING', String, 'Days when this habit should be done. 0=Sunday,6=Saturday Multiple days must be separated by comma 1,2,4'
15
+ c.action do |args, options|
16
+ days = []
17
+ days = options.schedule.split(',').map(&:strip).map(&:to_i) unless options.schedule.nil?
14
18
  archive = Archive.new
15
19
  args.each do |habit|
16
- archive.add_habit(habit)
20
+ archive.add_habit(habit, days)
17
21
  end
18
22
  end
19
23
  end
@@ -76,3 +80,16 @@ command :do do |c|
76
80
  archive.save(habit, selected_date)
77
81
  end
78
82
  end
83
+
84
+ command :today do |c|
85
+ c.syntax = 'ht today'
86
+ c.summary = 'Shows the list of habits you should do today'
87
+ c.description = 'Shows the list of habits you should do today'
88
+ c.example 'description', 'ht today'
89
+ c.action do |_args, _options|
90
+ archive = Archive.new
91
+ puts 'Today you should do:'
92
+ day_of_the_week = Time.now.strftime('%w').to_i
93
+ archive.habits_per_day(day_of_the_week).each { |h| puts "* #{h}" }
94
+ end
95
+ end
data/habittracker.gemspec CHANGED
@@ -4,37 +4,37 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'habittracker/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "habittracker"
7
+ spec.name = 'habittracker'
8
8
  spec.version = Habittracker::VERSION
9
- spec.authors = ["Ignazio Calò"]
10
- spec.email = ["ignazioc@gmail.com"]
9
+ spec.authors = ['Ignazio Calò']
10
+ spec.email = ['ignazioc@gmail.com']
11
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"
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
16
 
17
17
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
18
  # to allow pushing to a single host or delete this section to allow pushing to any host.
19
19
  if spec.respond_to?(:metadata)
20
- spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
21
  else
22
- raise "RubyGems 2.0 or newer is required to protect against " \
23
- "public gem pushes."
22
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
23
+ 'public gem pushes.'
24
24
  end
25
25
 
26
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
27
  f.match(%r{^(test|spec|features)/})
28
28
  end
29
29
  spec.required_ruby_version = '~> 2.3'
30
30
 
31
- spec.bindir = "exe"
31
+ spec.bindir = 'exe'
32
32
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
- spec.require_paths = ["lib"]
33
+ spec.require_paths = ['lib']
34
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"
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
38
 
39
39
  spec.add_dependency 'commander'
40
40
  spec.add_dependency 'terminal-table'
@@ -1,11 +1,10 @@
1
1
  class Archive
2
-
3
2
  def initialize
4
3
  @db_file = File.join(ENV['HOME'], '/.ht')
5
4
  load_archive
6
5
  end
7
6
 
8
- def add_habit(habit)
7
+ def add_habit(habit, days = [])
9
8
  from = Date.new(Time.now.year, 1, 1)
10
9
  to = Date.new(Time.now.year, 12, 31)
11
10
 
@@ -13,6 +12,8 @@ class Archive
13
12
  mem[date_to_key(day)] = false
14
13
  mem
15
14
  end
15
+ @archive[habit][:schedule] = days
16
+
16
17
  store
17
18
  load_archive
18
19
  end
@@ -58,6 +59,12 @@ class Archive
58
59
  load_archive
59
60
  end
60
61
 
62
+ def habits_per_day(day)
63
+ @archive.keys.select do |habit|
64
+ @archive[habit][:schedule].include?(day)
65
+ end
66
+ end
67
+
61
68
  #-- Private Methods
62
69
 
63
70
  private def load_archive
@@ -67,7 +74,7 @@ class Archive
67
74
  end
68
75
  end
69
76
  @archive = YAML.load_file(@db_file)
70
- end
77
+ end
71
78
 
72
79
  private def store
73
80
  File.open(@db_file, 'w') do |file|
@@ -92,6 +99,4 @@ class Archive
92
99
  private def row_item(value)
93
100
  value ? { value: 'X', alignment: :center } : { value: '', alignment: :center }
94
101
  end
95
-
96
-
97
102
  end
@@ -1,3 +1,3 @@
1
1
  module Habittracker
2
- VERSION = "0.1.0"
2
+ VERSION = '0.1.1'.freeze
3
3
  end
data/lib/habittracker.rb CHANGED
@@ -1,5 +1,5 @@
1
- require "habittracker/version"
2
- require "habittracker/archive"
1
+ require 'habittracker/version'
2
+ require 'habittracker/archive'
3
3
  require 'yaml'
4
4
  require 'date'
5
5
  require 'terminal-table'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: habittracker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ignazio Calò
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-17 00:00:00.000000000 Z
11
+ date: 2017-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler