hbtrack 0.0.6 → 0.0.7

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: 36d2ea881a273459943278a8ed55e05162544426
4
- data.tar.gz: 05f7cb9199065ab8eca1f558a4d7bda5dc971341
3
+ metadata.gz: d846c3fab2b780d7be575138918e3cbf97b6dc7d
4
+ data.tar.gz: 8b329428683139a92294fa6ba8bebc1b5611ab1f
5
5
  SHA512:
6
- metadata.gz: 17b23168d92bb400ff17d5b6685268fb5aafbf3ed2f27e9a8685dea89e56316e3af7a4af0ab23f93ce1b525aab0d9746b84ac76714df560eb33ea03cf22cb5ba
7
- data.tar.gz: 73b292c9e40a08ed498879ebba2c1c88f82f17a5d902c84aa4074f404341b01e457bbdcfe96729bf32c8f2de87dedb80bc78e92ee3792a4c5a18d736633d68e4
6
+ metadata.gz: b845ed06eb8ae37e4857bda84bc691fee6f81f007bfb95f3ddf9e47691a762d88839e098834a22067fc838b6ab31144dea04151760b1026a1d6b1afd89a19f47
7
+ data.tar.gz: 880729c315b22e13509a0fe1cc9bbf20a4ada8f0255d4f10082649f0e3772fd107d4a7fb2ceed035cfa71cc42c11da09cfe26afd41c91dc600bf176763d9da47
data/README.md CHANGED
@@ -1,4 +1,8 @@
1
- # Hbtrack [![Gem Version](https://badge.fury.io/rb/hbtrack.svg)](https://badge.fury.io/rb/hbtrack) [![Build Status](https://travis-ci.org/kw7oe/hbtrack.svg?branch=master)](https://travis-ci.org/kw7oe/hbtrack)
1
+ # Hbtrack
2
+ [![Gem Version](https://badge.fury.io/rb/hbtrack.svg)](https://badge.fury.io/rb/hbtrack)
3
+ [![Build Status](https://travis-ci.org/kw7oe/hbtrack.svg?branch=master)](https://travis-ci.org/kw7oe/hbtrack)
4
+ [![Code Climate](https://codeclimate.com/github/kw7oe/hbtrack/badges/gpa.svg)](https://codeclimate.com/github/kw7oe/hbtrack)
5
+
2
6
 
3
7
  `hbtrack` is a simple command lines tool to keep track of your daily habits. The functionality of the current version is very limited.
4
8
 
@@ -35,7 +39,7 @@ Options:
35
39
  - remaining habits of as done/undone
36
40
  - habit(s) as done for specific day with `--day DAY`
37
41
  - [x] Remove single or multiple habits at once
38
- - [x] Generate report in HTML format. *(In Progress)*
42
+ - [ ] Generate report in HTML format. *(In Progress)*
39
43
 
40
44
  ## Output
41
45
 
data/hbtrack.gemspec CHANGED
@@ -24,7 +24,6 @@ Gem::Specification.new do |spec|
24
24
  spec.require_paths = ['lib']
25
25
 
26
26
  spec.add_development_dependency 'bundler', '~> 1.14'
27
- spec.add_development_dependency 'minitest', '~> 5.10'
28
27
  spec.add_development_dependency 'rspec', '~> 3.6'
29
28
  spec.add_development_dependency 'rake', '~> 10.0'
30
29
  end
@@ -38,7 +38,7 @@ module Hbtrack
38
38
  @day = Date.today - 1
39
39
  end
40
40
 
41
- opts.on('--day DAY', OptionParser::OctalInteger, "#{action} habit(s) for specific day") do |day|
41
+ opts.on('--day DAY', Integer, "#{action} habit(s) for specific day") do |day|
42
42
  @day = Date.new(Date.today.year, Date.today.month, day.to_i)
43
43
  end
44
44
 
@@ -52,17 +52,11 @@ module Hbtrack
52
52
  end
53
53
 
54
54
  def done_count_for(date:)
55
- habits.reduce(0) do |a, habit|
56
- val = habit.done_for(date: date) == '1' ? 1 : 0
57
- a + val
58
- end
55
+ count_for(date, '1')
59
56
  end
60
57
 
61
58
  def undone_count_for(date:)
62
- habits.reduce(0) do |a, habit|
63
- val = habit.done_for(date: date) == '0' ? 1 : 0
64
- a + val
65
- end
59
+ count_for(date, '0')
66
60
  end
67
61
 
68
62
  def overall_stat_description(formatter)
@@ -85,5 +79,13 @@ module Hbtrack
85
79
  habit_name.nil? || habit_name =~ /\s+/ ||
86
80
  habit_name.length > 11
87
81
  end
82
+
83
+ private def count_for(d, value)
84
+ habits.reduce(0) do |a, habit|
85
+ val = habit.done_for(date: d) == value ? 1 : 0
86
+ a + val
87
+ end
88
+ end
89
+
88
90
  end
89
91
  end
data/lib/hbtrack/util.rb CHANGED
@@ -19,6 +19,7 @@ module Hbtrack
19
19
  value + string + "\e[0m"
20
20
  end
21
21
  end
22
+
22
23
  # Format the string with title style.
23
24
  #
24
25
  # @param string [String] the string to be styled as title
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hbtrack
4
- VERSION = '0.0.6'
4
+ VERSION = '0.0.7'
5
5
  end
data/lib/hbtrack.rb CHANGED
@@ -9,7 +9,6 @@ require 'hbtrack/command/list_command'
9
9
  require 'hbtrack/command/update_command'
10
10
  require 'hbtrack/command/remove_command'
11
11
  require 'hbtrack/command/add_command'
12
- require 'hbtrack/report/generator'
13
12
  require 'hbtrack/error_handler'
14
13
 
15
14
  module Hbtrack
@@ -27,9 +26,6 @@ module Hbtrack
27
26
  RemoveCommand.new(hbt, args)
28
27
  when 'add'
29
28
  AddCommand.new(hbt, args)
30
- when 'generate'
31
- Generator.new(hbt).generate
32
- exit
33
29
  else
34
30
  help
35
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hbtrack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - kw7oe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-17 00:00:00.000000000 Z
11
+ date: 2017-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.14'
27
- - !ruby/object:Gem::Dependency
28
- name: minitest
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '5.10'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '5.10'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rspec
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -95,9 +81,6 @@ files:
95
81
  - lib/hbtrack/habit.rb
96
82
  - lib/hbtrack/habit_printer.rb
97
83
  - lib/hbtrack/habit_tracker.rb
98
- - lib/hbtrack/report/calendar.rb
99
- - lib/hbtrack/report/generator.rb
100
- - lib/hbtrack/report/report.html.erb
101
84
  - lib/hbtrack/stat_formatter.rb
102
85
  - lib/hbtrack/store.rb
103
86
  - lib/hbtrack/util.rb
@@ -1,84 +0,0 @@
1
- module Hbtrack
2
- class Calendar
3
-
4
- WEEKDAYS = [
5
- "Mon",
6
- "Tue",
7
- "Wed",
8
- "Thu",
9
- "Fri",
10
- "Sat",
11
- "Sun"
12
- ]
13
-
14
- # Generate weeks of the current month,
15
- # which contains 7 days.
16
- def self.weeks(date)
17
- range = date.beginning_of_month..date.end_of_month
18
- result = range.chunk_while { |date| date.cwday < 7 }.to_a
19
-
20
- if result.first.length < 7
21
- (7 - result.first.length).times do
22
- result.first.unshift(NullDay.new)
23
- end
24
- end
25
-
26
- if result.last.length < 7
27
- (7 - result.last.length).times do
28
- result.last.push(NullDay.new)
29
- end
30
- end
31
-
32
- result
33
- end
34
-
35
- # Generate <td> elements for days
36
- def self.td_for(date, progress)
37
- progress = progress.split("")
38
-
39
- className = if date.day.nil?
40
- "null_day"
41
- elsif progress[date.day - 1] == "1"
42
- "done"
43
- elsif progress[date.day - 1] == "0"
44
- "undone"
45
- end
46
-
47
- string = <<~EOF
48
- <td>
49
- <p class="#{className}">
50
- #{add_padding_to(date.day)}
51
- </p>
52
- </td>
53
- EOF
54
- end
55
-
56
- def self.add_padding_to(day)
57
- return nil if day.nil?
58
- return "0#{day}" if day < 10
59
- day.to_s
60
- end
61
-
62
- end
63
-
64
- # Null Object Pattern
65
- class NullDay
66
- attr_reader :day
67
- def initialize
68
- @day = nil
69
- end
70
- end
71
-
72
-
73
- end
74
-
75
- # Extend Date Class
76
- class Date
77
- def beginning_of_month
78
- Date.new(self.year, self.month, 1)
79
- end
80
-
81
- def end_of_month
82
- Date.new(self.year, self.month, -1)
83
- end
84
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'erb'
4
- require 'hbtrack/report/calendar'
5
-
6
- module Hbtrack
7
- class Generator
8
- def initialize(hbt)
9
- @hbt = hbt
10
- initialize_stat
11
- @week_days = Hbtrack::Calendar::WEEKDAYS
12
- @weeks = Hbtrack::Calendar.weeks(Date.today)
13
- end
14
-
15
- def initialize_stat
16
- @stat = @hbt.total_habits_stat
17
- @stat[:total] = @stat[:done] + @stat[:undone]
18
- @stat[:percentage] = (@stat[:done] / @stat[:total].to_f).round(2) * 100
19
- end
20
-
21
- def td_for(date)
22
- Hbtrack::Calendar.td_for(date, @hbt.habits.last.latest_progress)
23
- end
24
-
25
- def generate
26
- file_path = File.expand_path("../report.html.erb", __FILE__)
27
- renderer = ERB.new(File.read(file_path))
28
- File.write('report.html', renderer.result(binding))
29
- end
30
- end
31
- end
@@ -1,89 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title></title>
5
- <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.5.2/css/bulma.min.css">
6
-
7
- <style type="text/css">
8
- .text-center { margin-top: 10%; text-align: center; }
9
-
10
- .calender { margin: 0 auto; width: 400px; height: 374.8571428571px; padding: 16px 18px; border: 1px solid #B3B3B3; overflow: hidden; }
11
- .calender table { border-collapse: collapse; }
12
- .calender .weekdays th { text-align: center; vertical-align: middle; text-transform: uppercase; height: 57.1428571429px; width: 57.1428571429px; }
13
- .calender .days { height: 57.1428571429px; width: 57.1428571429px; }
14
- .calender .days td { text-align: center; cursor: pointer; }
15
- .calender .days td p { border-radius: 50%; width: 44px; height: 44px; margin: 0; display: inline-block; text-align: center; padding: 10px; }
16
- .calender .days td p.null_day { display: none; }
17
- .calender .days td p.undone { color: white; background-color: #FF1654; }
18
- .calender .days td p.done { color: white; background-color: #70C1B3; }
19
- .calender .days td:hover p { background-color: #E6E6E6; }
20
- .calender .days td:hover p.undone { background-color: #CC1243; }
21
- .calender .days td:hover p.done { background-color: #549187; }
22
- </style>
23
- </head>
24
-
25
- <body>
26
- <!-- Title -->
27
- <section class="section">
28
- <div class="container">
29
- <div class="columns is-centered">
30
- <h1 class="title">Hbtrack</h1>
31
- </div>
32
- </div>
33
- </section>
34
-
35
- <!-- Calendar -->
36
- <section class="section>">
37
- <div class = "calender">
38
- <table>
39
- <!-- Generate Week Days -->
40
- <tr class = "weekdays">
41
- <% @week_days.each do |day| %>
42
- <th><%= day %></th>
43
- <% end %>
44
- </tr>
45
-
46
- <!-- Generate Days -->
47
- <% @weeks.each do |week| %>
48
- <tr class = "days">
49
- <% week.each do |day| %>
50
- <%= td_for(day) %>
51
- <% end %>
52
- </tr>
53
- <% end %>
54
- </table>
55
- </div>
56
- </section>
57
-
58
- <!-- Stat -->
59
- <section class="section">
60
- <nav class="level">
61
- <div class="level-item has-text-centered">
62
- <div>
63
- <p class="heading">Total</p>
64
- <p class="title"><%= @stat[:total] %></p>
65
- </div>
66
- </div>
67
- <div class="level-item has-text-centered">
68
- <div>
69
- <p class="heading">Done</p>
70
- <p class="title"><%= @stat[:done] %></p>
71
- </div>
72
- </div>
73
- <div class="level-item has-text-centered">
74
- <div>
75
- <p class="heading">Undone</p>
76
- <p class="title"><%= @stat[:undone] %></p>
77
- </div>
78
- </div>
79
- <div class="level-item has-text-centered">
80
- <div>
81
- <p class="heading">Completion Rate</p>
82
- <p class="title"><%= @stat[:percentage] %>%</p>
83
- </div>
84
- </div>
85
- </nav>
86
- </section>
87
- <!-- End of Stat -->
88
- </body>
89
- </html>