bentrackergem 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +16 -2
- data/bentrackergem.gemspec +1 -0
- data/lib/bentrackergem.rb +15 -4
- data/lib/bentrackergem/version.rb +1 -1
- data/spec/bentrackergem_spec.rb +24 -7
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f74e9d9fa978f6ac460b7660b414ef0b770f5099
|
4
|
+
data.tar.gz: 7438ac0d05316e42098eddfc4255999d9cb4797d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ed3d9bb3f27df18459162aaafc8b3a43a5d408824cf3a93b937e64f819c37ee0ef23962ac84941ab002c9380a1c9fde641aae429d37038a485d43c5a146fc85
|
7
|
+
data.tar.gz: 8662a87258dee5c1e1a20e587240fe1c87d85fbd3346e7a6e204e5ec83963a2fa77b3a79cf1946d1f05f635717f5b4a93323e1a8a6691b1e6797574669209f9e
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -18,11 +18,25 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
Post today's summary:
|
22
|
+
|
23
|
+
`BenTrackerGem.post_message("What a great day!")`
|
24
|
+
|
25
|
+
Get today's stats:
|
26
|
+
|
27
|
+
`BenTrackerGem.day_stats("2014-10-06")`
|
28
|
+
|
29
|
+
Get multiple days of stats:
|
30
|
+
|
31
|
+
`BenTrackerGem.date_range("2014-09-30", "2014-10-05")`
|
32
|
+
|
33
|
+
Get visual output of specific category:
|
34
|
+
|
35
|
+
`BenTrackerGem.date_range_visual("code", "2014-10-03", "2014-10-06")`
|
22
36
|
|
23
37
|
## Contributing
|
24
38
|
|
25
|
-
1. Fork it ( https://github.com/
|
39
|
+
1. Fork it ( https://github.com/benbrostoff/bentrackergem/fork )
|
26
40
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
41
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
42
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/bentrackergem.gemspec
CHANGED
data/lib/bentrackergem.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "bentrackergem/version"
|
2
|
+
require "chronic"
|
2
3
|
require "rest_client"
|
3
4
|
require "json"
|
4
5
|
require "date"
|
@@ -7,9 +8,12 @@ module BenTrackerGem
|
|
7
8
|
|
8
9
|
URL_GET = 'http://brostofftrack.herokuapp.com/history.json'
|
9
10
|
URL_POST = 'http://brostofftrack.herokuapp.com/email'
|
10
|
-
HISTORY = JSON.parse(RestClient.get URL_GET).to_h["days"]
|
11
11
|
|
12
12
|
VALID_CATS = ["message", "code", "fitness"]
|
13
|
+
|
14
|
+
def self.get_history
|
15
|
+
JSON.parse(RestClient.get URL_GET).to_h["days"]
|
16
|
+
end
|
13
17
|
|
14
18
|
def self.valid_format(date)
|
15
19
|
date = DateTime.parse(date, "%Y-%m-%d").to_s[0..9]
|
@@ -29,7 +33,7 @@ module BenTrackerGem
|
|
29
33
|
|
30
34
|
def self.day_stats(date)
|
31
35
|
date = valid_format(date)
|
32
|
-
|
36
|
+
get_history.each do |summary|
|
33
37
|
if summary["day_of"] == date
|
34
38
|
return filter_hash(summary)
|
35
39
|
end
|
@@ -38,9 +42,10 @@ module BenTrackerGem
|
|
38
42
|
|
39
43
|
def self.date_range(begin_date, end_date)
|
40
44
|
begin_date, end_date, hold = valid_format(begin_date), valid_format(end_date), []
|
41
|
-
filter =
|
45
|
+
filter = get_history.select { |summary| summary["day_of"] >= begin_date &&
|
42
46
|
summary["day_of"] <= end_date }.
|
43
|
-
map { |summary| day_stats(summary["day_of"]) }
|
47
|
+
map { |summary| day_stats(summary["day_of"]) }.
|
48
|
+
sort_by { |summary| summary[:day_of] }
|
44
49
|
end
|
45
50
|
|
46
51
|
def self.date_range_visual(req, begin_date, end_date, sort = 0)
|
@@ -54,6 +59,12 @@ module BenTrackerGem
|
|
54
59
|
"COMPLETE"
|
55
60
|
end
|
56
61
|
|
62
|
+
def self.diary(begin_date = "last week", end_date = "today")
|
63
|
+
date_range_visual("message",
|
64
|
+
Chronic.parse(begin_date).to_s[0..9],
|
65
|
+
Chronic.parse(end_date).to_s[0..9])
|
66
|
+
end
|
67
|
+
|
57
68
|
def self.post_message(message)
|
58
69
|
raise ArgumentError, "must enter message as String" if !message.is_a? String
|
59
70
|
|
data/spec/bentrackergem_spec.rb
CHANGED
@@ -59,11 +59,12 @@ describe 'BenTrackerGem' do
|
|
59
59
|
|
60
60
|
context "#date_range" do
|
61
61
|
|
62
|
-
it "should return an array of day summaries given valid begin and end dates" do
|
63
|
-
expect(BenTrackerGem.date_range("2014-10-
|
64
|
-
[BenTrackerGem.day_stats("2014-10-
|
65
|
-
BenTrackerGem.day_stats("2014-10-
|
66
|
-
BenTrackerGem.day_stats("2014-10-
|
62
|
+
it "should return an array of day summaries given valid begin and end dates in chronological order" do
|
63
|
+
expect(BenTrackerGem.date_range("2014-10-08", "2014-10-11")).to eq(
|
64
|
+
[BenTrackerGem.day_stats("2014-10-08"),
|
65
|
+
BenTrackerGem.day_stats("2014-10-09"),
|
66
|
+
BenTrackerGem.day_stats("2014-10-10"),
|
67
|
+
BenTrackerGem.day_stats("2014-10-11")]
|
67
68
|
)
|
68
69
|
end
|
69
70
|
|
@@ -73,13 +74,29 @@ describe 'BenTrackerGem' do
|
|
73
74
|
|
74
75
|
it "should raise an error if user requests invalid category" do
|
75
76
|
expect{
|
76
|
-
|
77
|
+
BenTrackerGem.date_range_visual("COO", "2014-10-03", "2014-10-05")
|
77
78
|
}.to raise_error(ArgumentError, "must select valid category")
|
78
79
|
end
|
79
80
|
|
80
81
|
it "should execute without error when valid category and dates are input" do
|
81
82
|
expect(
|
82
|
-
|
83
|
+
BenTrackerGem.date_range_visual("message", "2014-10-08", "2014-10-15")
|
84
|
+
).to eq("COMPLETE")
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
context "#diary" do
|
90
|
+
|
91
|
+
it "should replicate #date_range_visual with last week's info by default" do
|
92
|
+
expect(
|
93
|
+
BenTrackerGem.diary
|
94
|
+
).to eq("COMPLETE")
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should allow for optional arguments" do
|
98
|
+
expect(
|
99
|
+
BenTrackerGem.diary("three days ago", "today")
|
83
100
|
).to eq("COMPLETE")
|
84
101
|
end
|
85
102
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bentrackergem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Brostoff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: chronic
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
description: Leverages FitBit and GitHub to track fitness and code; messages can be
|
98
112
|
input via the command line and are emailed to me via the Mandrill API.
|
99
113
|
email:
|