trackstar 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +98 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/bin/trackstar +63 -0
- data/lib/trackstar.rb +24 -0
- data/lib/trackstar/log.rb +84 -0
- data/lib/trackstar/log_helper.rb +173 -0
- data/lib/trackstar/post.rb +79 -0
- data/lib/trackstar/templates/practice_log.yaml +3 -0
- data/lib/trackstar/version.rb +3 -0
- data/trackstar.gemspec +25 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ada21c1ba3d9cd60dc943eea6ce03b59ec6cf5ea9f069dd7cb7a416a5ee8d808
|
4
|
+
data.tar.gz: ce4165369847b97f0897fb5b61195428f96a6109d413213cb23d921b9ad1d666
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b6bdf075978ebe3c93d3ad1cec4929d6dc44dfbdbe26219e0415a54905410adfb60cf7fa5d9a1c1184bec4358552bab5d6b591ad5d8c5594f7e4de4f1e2c11d7
|
7
|
+
data.tar.gz: fa9424fa98d9634d791514c27f17949bf699d5da7659db3c4b9d55b7bfe368b8451c342b2aecfacc045aa0a96ee0168f6cefbe0762ae8516d118a76fca8ecd48
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Dave
|
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
|
+
# Trackstar 🏃♂️
|
2
|
+
|
3
|
+
*Track things. Like a star!*
|
4
|
+
|
5
|
+
Trackstar is a simple, command line based practice tracker. It creates human-readable Markdown files for every entry in your log.
|
6
|
+
|
7
|
+
Use the built in stats functionality to get some insights. If you need to edit or review entries, just open up the files.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
```
|
12
|
+
$ gem install trackstar
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
### Create a new Trackstar log
|
18
|
+
|
19
|
+
```
|
20
|
+
$ trackstar -n "Guitar Practice"
|
21
|
+
```
|
22
|
+
|
23
|
+
This will create a directory for your log, a trackstar.yaml config file, and a directory called `posts` where all of your entries will go.
|
24
|
+
|
25
|
+
### Create a new post in an existing Trackstar log
|
26
|
+
|
27
|
+
To write new posts in your log, you will to run the `trackstar` command from within your log directory. When you write a new log, a new Markdown file will be created in the `posts` directory.
|
28
|
+
|
29
|
+
```
|
30
|
+
$ trackstar
|
31
|
+
New Post For Aug 19 2017 10:09 pm:
|
32
|
+
---------------------
|
33
|
+
subject:
|
34
|
+
...
|
35
|
+
```
|
36
|
+
|
37
|
+
### Get log stats
|
38
|
+
```
|
39
|
+
$ trackstar -l
|
40
|
+
```
|
41
|
+
|
42
|
+
### List recent posts
|
43
|
+
```
|
44
|
+
$ trackstar -l # lists the 10 most recent posts
|
45
|
+
...
|
46
|
+
$ trackstar -l 5 # lists the 5 most recent posts
|
47
|
+
...
|
48
|
+
```
|
49
|
+
|
50
|
+
### Need more help?
|
51
|
+
|
52
|
+
```
|
53
|
+
$ trackstar -h
|
54
|
+
```
|
55
|
+
|
56
|
+
## Customisation
|
57
|
+
|
58
|
+
### Editing Post Fields
|
59
|
+
|
60
|
+
You can change the fields used in your Trackstar log by editing the `post_fields` values in the `trackstar.yaml` config file. The format is:
|
61
|
+
```yaml
|
62
|
+
post_fields:
|
63
|
+
field_name: conversation_method
|
64
|
+
```
|
65
|
+
where `conversation_method` is a Ruby String method for type conversion.
|
66
|
+
|
67
|
+
### Editing Post Formatting
|
68
|
+
|
69
|
+
You can add formatting to the post Markdown by editing the `post_formatting` values in the `trackstar.yaml` config file. The format is:
|
70
|
+
```yaml
|
71
|
+
post_formatting:
|
72
|
+
field_name: formatting_method
|
73
|
+
```
|
74
|
+
where `formatting_method` is a method implemented in the `Trackstar::Post` class to add formatting after a field.
|
75
|
+
|
76
|
+
Currently supported formatting methods:
|
77
|
+
- `hr_after`: Adds a horizontal rule after the field
|
78
|
+
|
79
|
+
## Development
|
80
|
+
|
81
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
82
|
+
|
83
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
84
|
+
|
85
|
+
### Testing
|
86
|
+
|
87
|
+
To run tests:
|
88
|
+
```
|
89
|
+
$ rake test
|
90
|
+
```
|
91
|
+
|
92
|
+
## Contributing
|
93
|
+
|
94
|
+
1. Fork it ( https://github.com/dorkrawk/trackstar/fork )
|
95
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
96
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
97
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
98
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "trackstar"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/bin/trackstar
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# require 'trackstar'
|
4
|
+
require_relative '../lib/trackstar'
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
options = {
|
8
|
+
post: true,
|
9
|
+
new: false,
|
10
|
+
destroy: false,
|
11
|
+
stats: false,
|
12
|
+
list: false,
|
13
|
+
limit: 10
|
14
|
+
}
|
15
|
+
|
16
|
+
OptionParser.new do |opts|
|
17
|
+
opts.banner = %(
|
18
|
+
Usage:
|
19
|
+
trackstar [options]
|
20
|
+
|
21
|
+
Example:
|
22
|
+
trackstar -n # creates new Trackstar log
|
23
|
+
trackstar # creates new Trackstar post in an existing Log
|
24
|
+
)
|
25
|
+
|
26
|
+
opts.on '-n', '--new', 'Create new Trackstar log' do
|
27
|
+
options[:post] = false
|
28
|
+
options[:new] = true
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on '-d', '--destroy', 'Destroys the current Trackstar log' do
|
32
|
+
options[:post] = false
|
33
|
+
options[:destroy] = true
|
34
|
+
end
|
35
|
+
|
36
|
+
opts.on '-s', '--stats', 'Show stats from the current Trackstar log' do
|
37
|
+
options[:post] = false
|
38
|
+
options[:stats] = true
|
39
|
+
end
|
40
|
+
|
41
|
+
opts.on '-l [LIMIT]', '--list [LIMIT]', Integer, 'Lists recent eosts from current Trackstar log. Default limit is 10' do |limit|
|
42
|
+
options[:post] = false
|
43
|
+
options[:list] = true
|
44
|
+
if limit && limit.to_i.positive?
|
45
|
+
options[:limit] = limit
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
opts.on_tail '-v', '--version', 'Show version' do
|
50
|
+
options[:post] = false
|
51
|
+
puts "trackstar v#{Trackstar::VERSION}"
|
52
|
+
exit
|
53
|
+
end
|
54
|
+
|
55
|
+
opts.on_tail '-h', '--help', 'I think you know what this does...' do
|
56
|
+
options[:post] = false
|
57
|
+
puts opts
|
58
|
+
exit
|
59
|
+
end
|
60
|
+
|
61
|
+
end.parse!
|
62
|
+
|
63
|
+
Trackstar.call(options)
|
data/lib/trackstar.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative "trackstar/version"
|
2
|
+
require_relative "trackstar/post"
|
3
|
+
require_relative "trackstar/log_helper"
|
4
|
+
require_relative "trackstar/log"
|
5
|
+
|
6
|
+
module Trackstar
|
7
|
+
def self.call(options)
|
8
|
+
if options[:new]
|
9
|
+
Trackstar::LogHelper.setup_log
|
10
|
+
elsif Trackstar::LogHelper.check_for_existing_log(Dir.pwd)
|
11
|
+
if options[:destroy]
|
12
|
+
Trackstar::LogHelper.destroy_log
|
13
|
+
elsif options[:stats]
|
14
|
+
Trackstar::LogHelper.show_stats
|
15
|
+
elsif options[:post]
|
16
|
+
Trackstar::LogHelper.create_post
|
17
|
+
elsif options[:list]
|
18
|
+
Trackstar::LogHelper.list_posts(options[:limit])
|
19
|
+
end
|
20
|
+
else
|
21
|
+
Trackstar::LogHelper.missing_log
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'active_support/core_ext'
|
2
|
+
|
3
|
+
class Trackstar::Log
|
4
|
+
|
5
|
+
CONFIG_FILE_NAME = 'trackstar.yaml'
|
6
|
+
POSTS_DIR = 'posts'
|
7
|
+
DEFAULT_FIELDS = { subject: :to_s, hours: :to_f, notes: :to_s }
|
8
|
+
DEFAULT_FORMATTING = { hours: :hr_after }
|
9
|
+
|
10
|
+
attr_reader :name, :fields, :formatting
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@config_yaml = load_config_yaml
|
14
|
+
if @config_yaml['post_fields']
|
15
|
+
@fields = @config_yaml['post_fields'].transform_keys(&:to_sym).transform_values(&:to_sym)
|
16
|
+
else
|
17
|
+
@fields = DEFAULT_FIELDS
|
18
|
+
end
|
19
|
+
if @config_yaml['post_formatting']
|
20
|
+
@formatting = @config_yaml['post_formatting'].transform_keys(&:to_sym).transform_values(&:to_sym)
|
21
|
+
else
|
22
|
+
@formatting = DEFAULT_FORMATTING
|
23
|
+
end
|
24
|
+
@name = @config_yaml['log_name']
|
25
|
+
end
|
26
|
+
|
27
|
+
def build_post
|
28
|
+
new_post = Trackstar::Post.new
|
29
|
+
puts "New Post For #{@name}"
|
30
|
+
puts "#{new_post.values[:date]}"
|
31
|
+
puts "---------------------"
|
32
|
+
new_post.fields.each do |key, casting_method|
|
33
|
+
begin
|
34
|
+
puts "#{key}: "
|
35
|
+
new_post.values[key] = gets.chomp.send(casting_method)
|
36
|
+
rescue => e
|
37
|
+
puts "Sorry, that's not a valid input for #{key}. Let's try this again..."
|
38
|
+
retry
|
39
|
+
end
|
40
|
+
end
|
41
|
+
puts ""
|
42
|
+
new_post
|
43
|
+
end
|
44
|
+
|
45
|
+
def posts
|
46
|
+
@posts ||= Dir["#{POSTS_DIR}/*.md"].sort.map do |file|
|
47
|
+
Trackstar::Post.new(file)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def current_week_posts
|
52
|
+
start_of_week_timestamp = DateTime.now.beginning_of_week.to_time.to_i
|
53
|
+
@current_week_posts ||= posts.select { |p| p.values[:timestamp].to_i > start_of_week_timestamp }
|
54
|
+
end
|
55
|
+
|
56
|
+
# stats methods
|
57
|
+
|
58
|
+
def post_count
|
59
|
+
Dir["#{POSTS_DIR}/*"].count { |file| File.file?(file) }
|
60
|
+
end
|
61
|
+
|
62
|
+
def current_week_post_count
|
63
|
+
current_week_posts.count
|
64
|
+
end
|
65
|
+
|
66
|
+
def count_hours(post_list=posts)
|
67
|
+
post_list.map { |post| post.values[:hours].to_f }.inject(0, :+)
|
68
|
+
end
|
69
|
+
|
70
|
+
def total_hours
|
71
|
+
count_hours
|
72
|
+
end
|
73
|
+
|
74
|
+
def current_week_hours
|
75
|
+
count_hours(current_week_posts)
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
def load_config_yaml
|
80
|
+
config_path = File.join(Dir.pwd, CONFIG_FILE_NAME)
|
81
|
+
config = YAML.load_file(config_path)
|
82
|
+
config
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
require "yaml"
|
3
|
+
|
4
|
+
class Trackstar::LogHelper
|
5
|
+
|
6
|
+
CONFIG_FILE_NAME = 'trackstar.yaml'
|
7
|
+
POSTS_DIR = 'posts'
|
8
|
+
YESES = %w(y yes yep sure uhhuh ok)
|
9
|
+
|
10
|
+
def self.print_trackstar_logo
|
11
|
+
puts "*" * 15
|
12
|
+
puts "🏃♂️ Trackstar 🏃♂️"
|
13
|
+
puts "*" * 15
|
14
|
+
puts ""
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.set_up_install_path
|
18
|
+
install_path = Dir.pwd
|
19
|
+
existing_log = self.check_for_existing_log(install_path)
|
20
|
+
if existing_log
|
21
|
+
puts "There seems to already be a Trackstar log here."
|
22
|
+
false
|
23
|
+
else
|
24
|
+
install_path
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.check_for_existing_log(dir_path)
|
29
|
+
config_path = File.join(dir_path, CONFIG_FILE_NAME)
|
30
|
+
FileTest.exists?(config_path)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.config_yaml
|
34
|
+
config_path = File.join(Dir.pwd, CONFIG_FILE_NAME)
|
35
|
+
config = YAML.load_file(config_path)
|
36
|
+
config
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.missing_log
|
40
|
+
puts "Sorry, there doesn't seem to be a Trackstar log here."
|
41
|
+
puts "Enter `trackstar -n` to create a new log."
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.set_up_name
|
45
|
+
name = ""
|
46
|
+
while name.empty?
|
47
|
+
puts "So, what do you want to call this log?"
|
48
|
+
name = gets.chomp.to_s
|
49
|
+
end
|
50
|
+
name
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.stubify(string)
|
54
|
+
stub = string
|
55
|
+
stub.gsub(/[^0-9a-z ]/i, '').
|
56
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
57
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
58
|
+
tr('-', '_').
|
59
|
+
gsub(/\s/, '_').
|
60
|
+
gsub(/__+/, '_').
|
61
|
+
downcase
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.create_log(log_options)
|
65
|
+
base_path = log_options[:install_path]
|
66
|
+
FileUtils.mkdir_p(base_path)
|
67
|
+
self.create_config(log_options)
|
68
|
+
FileUtils.mkdir_p(File.join(base_path, POSTS_DIR))
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.create_config(log_options)
|
72
|
+
base_path = log_options[:install_path]
|
73
|
+
File.open(File.join(base_path, CONFIG_FILE_NAME), 'w') do |config_file|
|
74
|
+
config_file.puts "# Trackstar log config"
|
75
|
+
config_file.puts ""
|
76
|
+
config_file.puts "log_name: #{log_options[:name]}"
|
77
|
+
config_file.puts "stub: #{log_options[:name_stub]}"
|
78
|
+
config_file.puts "post_fields:"
|
79
|
+
Trackstar::Log::DEFAULT_FIELDS.each do |field_name, conversion_method|
|
80
|
+
config_file.puts " #{field_name.to_s}: #{conversion_method.to_s}"
|
81
|
+
end
|
82
|
+
config_file.puts "post_formatting:"
|
83
|
+
Trackstar::Log::DEFAULT_FORMATTING.each do |field_name, format|
|
84
|
+
config_file.puts " #{field_name.to_s}: #{format.to_s}"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.setup_log
|
90
|
+
self.print_trackstar_logo
|
91
|
+
log_options = {}
|
92
|
+
puts "Ok! Let's set up your Trackstar log!"
|
93
|
+
puts "------------------------------------"
|
94
|
+
log_options[:name] = self.set_up_name
|
95
|
+
log_options[:name_stub] = self.stubify(log_options[:name])
|
96
|
+
install_path_root = self.set_up_install_path
|
97
|
+
log_options[:install_path] = File.join(install_path_root, log_options[:name_stub])
|
98
|
+
puts "Here's what we're going to set up:"
|
99
|
+
puts " log name: #{log_options[:name]}"
|
100
|
+
puts " name stub: #{log_options[:name_stub]}"
|
101
|
+
puts " install location: #{log_options[:install_path]}"
|
102
|
+
puts ""
|
103
|
+
puts "Sounds good? (y/n)"
|
104
|
+
confirmation = gets.chomp.downcase
|
105
|
+
if YESES.include?(confirmation)
|
106
|
+
self.create_log(log_options)
|
107
|
+
puts "Ok, you're good to go."
|
108
|
+
else
|
109
|
+
puts "Ok, maybe next time."
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.destroy_log
|
114
|
+
self.print_trackstar_logo
|
115
|
+
puts "Whoa! We're going to destroy your Trackstar log."
|
116
|
+
post_count = self.post_count
|
117
|
+
puts "That means deleting all #{post_count} posts."
|
118
|
+
puts "Do you really want to do this? (y/n)"
|
119
|
+
confirmation = gets.chomp.downcase
|
120
|
+
if YESES.include?(confirmation)
|
121
|
+
system "rm #{CONFIG_FILE_NAME}"
|
122
|
+
system "rm -r #{POSTS_DIR}"
|
123
|
+
puts "BOOM. gone."
|
124
|
+
else
|
125
|
+
puts "Ok, this log lives another day."
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def self.create_post
|
130
|
+
self.print_trackstar_logo
|
131
|
+
log = Trackstar::Log.new
|
132
|
+
new_post = log.build_post
|
133
|
+
puts "Ok, here's your post:"
|
134
|
+
puts "-" * 10
|
135
|
+
new_post.preview
|
136
|
+
puts "-" * 10
|
137
|
+
puts "Look good? (y/n)"
|
138
|
+
confirmation = gets.chomp.downcase
|
139
|
+
if YESES.include?(confirmation)
|
140
|
+
post_file_name = new_post.persist!
|
141
|
+
puts "Post saved as #{post_file_name}"
|
142
|
+
else
|
143
|
+
puts "Try again? (y/n)"
|
144
|
+
confirmation = gets.chomp.downcase
|
145
|
+
self.create_post if YESES.include?(confirmation)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def self.list_posts(limit)
|
150
|
+
log = Trackstar::Log.new
|
151
|
+
puts "The #{limit} most recent posts from #{log.name}"
|
152
|
+
puts "-" * 10
|
153
|
+
log.posts.first(limit).reverse.each do |post|
|
154
|
+
puts "#{post.values[:date]}: #{post.values[:subject]}"
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def self.show_stats
|
159
|
+
self.print_trackstar_logo
|
160
|
+
log = Trackstar::Log.new
|
161
|
+
first_post = log.posts.first
|
162
|
+
last_post = log.posts.last
|
163
|
+
puts "Stats for #{log.name}"
|
164
|
+
puts "-" * 20
|
165
|
+
puts "total post count: #{log.post_count}"
|
166
|
+
puts "total hours: #{log.total_hours}"
|
167
|
+
puts "post count this week: #{log.current_week_post_count}"
|
168
|
+
puts "hours this week: #{log.current_week_hours}"
|
169
|
+
puts "first post: #{first_post.values[:date]} - #{first_post.values[:subject]}"
|
170
|
+
puts "last post: #{last_post.values[:date]} - #{last_post.values[:subject]}"
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
class Trackstar::Post
|
4
|
+
|
5
|
+
attr_accessor :values
|
6
|
+
attr_reader :fields, :formatting
|
7
|
+
|
8
|
+
def initialize(path = nil)
|
9
|
+
@log = Trackstar::Log.new
|
10
|
+
@fields = @log.fields
|
11
|
+
@formatting = @log.formatting
|
12
|
+
@values = {}
|
13
|
+
|
14
|
+
if path
|
15
|
+
load_from_path(path)
|
16
|
+
# note this doesn't load the text of the post
|
17
|
+
else
|
18
|
+
now = Time.now
|
19
|
+
@values[:timestamp] = now.to_i
|
20
|
+
@values[:date] = date_time_format(now)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def preview
|
25
|
+
@values.each do |key, value|
|
26
|
+
puts "#{key}: #{value}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def file_name
|
31
|
+
"#{@values[:timestamp]}-#{subject_stub}.md"
|
32
|
+
end
|
33
|
+
|
34
|
+
def subject_stub
|
35
|
+
Trackstar::LogHelper.stubify(@values[:subject])
|
36
|
+
end
|
37
|
+
|
38
|
+
def persist!
|
39
|
+
post_file_path = "#{Trackstar::LogHelper::POSTS_DIR}/#{file_name}"
|
40
|
+
File.open(post_file_path, 'w') do |post_file|
|
41
|
+
post_file.puts "date: #{@values[:date]}"
|
42
|
+
|
43
|
+
fields.keys.each do |field_name|
|
44
|
+
post_file.puts "#{field_name.to_s}: #{values[field_name]}"
|
45
|
+
if formatting.include? field_name
|
46
|
+
self.send(formatting[field_name], post_file)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
post_file_path
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def load_from_path(path)
|
56
|
+
pn = Pathname.new(path)
|
57
|
+
@values[:timestamp] = pn.basename.to_s.split('-').first
|
58
|
+
File.readlines(path).each do |line|
|
59
|
+
break if line[0] == "-"
|
60
|
+
line.gsub!(/\n?/, "")
|
61
|
+
split_line = line.split(": ")
|
62
|
+
key = split_line.first
|
63
|
+
value = split_line.last
|
64
|
+
@values[key.to_sym] = value
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
def date_time_format(timestamp)
|
70
|
+
timestamp.strftime("%b %e %Y %l:%M %P")
|
71
|
+
end
|
72
|
+
|
73
|
+
# persisted post formatting methods
|
74
|
+
|
75
|
+
def hr_after(file_handle)
|
76
|
+
file_handle.puts "-" * 20
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
data/trackstar.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'trackstar/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "trackstar"
|
8
|
+
spec.version = Trackstar::VERSION
|
9
|
+
spec.authors = ["Dave"]
|
10
|
+
spec.email = ["dave.schwantes@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "A commandline based progress tracker."
|
13
|
+
spec.description = "Create a simple log and track your practice hours from the commandline."
|
14
|
+
spec.homepage = "https://github.com/dorkrawk/trackstar"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.executables = ['trackstar']
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "activesupport", "~> 6.0.2"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler"
|
24
|
+
spec.add_development_dependency "rake", "~> 12.3"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trackstar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dave
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-04-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 6.0.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 6.0.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '12.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '12.3'
|
55
|
+
description: Create a simple log and track your practice hours from the commandline.
|
56
|
+
email:
|
57
|
+
- dave.schwantes@gmail.com
|
58
|
+
executables:
|
59
|
+
- trackstar
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- CODE_OF_CONDUCT.md
|
67
|
+
- Gemfile
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- bin/trackstar
|
74
|
+
- lib/trackstar.rb
|
75
|
+
- lib/trackstar/log.rb
|
76
|
+
- lib/trackstar/log_helper.rb
|
77
|
+
- lib/trackstar/post.rb
|
78
|
+
- lib/trackstar/templates/practice_log.yaml
|
79
|
+
- lib/trackstar/version.rb
|
80
|
+
- trackstar.gemspec
|
81
|
+
homepage: https://github.com/dorkrawk/trackstar
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubygems_version: 3.1.2
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: A commandline based progress tracker.
|
104
|
+
test_files: []
|