aggtive_record 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjRjOWFmN2Y1ZWRmNDIzNTdkMTAxODUwZmRlYWMyOTZlN2Y5NzQ2Ng==
4
+ YmZlNDM4YTRiZTMwOGVlZjYwOWIwOWE2NmExNTAzODEzNTA0ZmI1OQ==
5
5
  data.tar.gz: !binary |-
6
- MzJhZmRhZDRhZmQzMDM3YWEzNTFjZTM2NGYzMzJmZGM5ZmM0NjQ4ZQ==
6
+ MDQwZjE3ZWQ0ZTZhNDgwY2RhNzMwOTI5YzM1NDU0NjcwNDRhN2FlMQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZTY5N2YxNTlkMDEwMjM5MDkzOGNhMmI2NmM2Y2JiNmU0NDIwMGIxY2U2ZWI1
10
- NDI5ZWNmY2EwOGE0ZDBmZWZmZjgwYjAxZWUwOTA1YjhhN2FkZDgwOGYxNDY3
11
- NWZhYTY0ZTgxMjE0ZjU0N2RiMDJhZmVmYmYyZWVmMGM0YjAxNzM=
9
+ YzA2YjM5ZjVkMTlmMjViMTBmOTQwNjBjODUzMTJiZDRiNmM5ODBmMTYxNzc0
10
+ NTllNDc4ZGJkZmQ0ZTRiOGJkMTdjZTIwOWMyYWZhMDA4MDA0ZGY5ZDM0Y2Rk
11
+ MTNiNGI0ZDk2OGUxYjFjNDkyMWU3MDBiY2Y3MzEyNTkxNWFmY2E=
12
12
  data.tar.gz: !binary |-
13
- Yzc2ZjgwZjZmM2EyMTE4ZmM5ZWI4YTFhMTFjYmEzNTNlM2I2MzM2MTVlODhh
14
- ZDQ2ODgxYTU4OTljMWZhMTc0YzcwMDA2ZDVhZmU4YzYxN2FjY2Y2M2U4MjMy
15
- NTA3NTUwMzRlMWM3OGMzNDIwMDE2ZjYwM2MwZTU2ZmEzZTI2ZWE=
13
+ ODBiNTU3ZTBmN2E2YzJkNGMyMjAwODY4MjY3NzU1OGYzM2ViYzFhMzI3Y2Qw
14
+ YjA5NmZlMDkzMzcxZGE5NzI2ZTRkMzc3MDI3YmY3OWQ3YWE0NTU4ODAxOTIx
15
+ Mzk2ZjQwMWJmOGM2ZGU5ZmUyOGJlODJiYTljMWY1YWQzOTNkZWE=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "aggtive_record"
8
- s.version = "0.2.1"
8
+ s.version = "0.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dan Nguyen"]
@@ -35,6 +35,7 @@ module AggtiveRecord
35
35
  end
36
36
 
37
37
  def timespan_to_now(records)
38
+ return 0 if records.empty? || records.nil?
38
39
  ::Time.now - earliest_time_of(records)
39
40
  end
40
41
 
@@ -14,17 +14,19 @@ module AggtiveRecord
14
14
  #
15
15
  # Returns float indicating rate of records per given time period
16
16
  def rate_per(time_period, timespan_in_seconds = nil)
17
+
17
18
  # tk: this may be unnecessary
18
19
  records = self.scoped.to_a
19
20
 
20
- # eg. :hour is 3600 seconds
21
- time_period_in_secs = AggtiveRecord::Time.to_seconds(time_period)
22
-
23
- #e.g. whatever is passed in, or all of them from the beginning to end of reconrds
21
+ #e.g. whatever is passed in, or all of them from the beginning to end of reconrds
24
22
  timespan_in_seconds ||= self.timespan_to_now(records)
25
23
 
26
-
24
+ # return 0 if no timespan_in_seconds
25
+ return 0 if timespan_in_seconds.to_i ==0
27
26
 
27
+ # eg. :hour is 3600 seconds
28
+ time_period_in_secs = AggtiveRecord::Time.to_seconds(time_period)
29
+
28
30
  return records.size.to_f * time_period_in_secs / timespan_in_seconds
29
31
  end
30
32
 
@@ -3,6 +3,30 @@ require 'spec_helper'
3
3
 
4
4
  describe AggtiveRecord do
5
5
 
6
+ context 'collation with zero' do
7
+
8
+ describe '.rate_by' do
9
+ it 'should return rates of 0 with no records' do
10
+
11
+ expect(MusicRecord.rate_per_week(:past_month)).to eq 0
12
+ expect(MusicRecord.rate_per_hour(:past_year)).to eq 0
13
+ expect(MusicRecord.rate_per_hour(:overall)).to eq 0
14
+ end
15
+ end
16
+
17
+ describe '.past_' do
18
+ it 'should be empty with no records' do
19
+ expect(MusicRecord.past_year).to be_empty
20
+ end
21
+ end
22
+
23
+ describe '.count_by' do
24
+ it 'should be empty with no records' do
25
+ expect(MusicRecord.count_by_month).to be_empty
26
+ expect(MusicRecord.past_year.count_by_month).to be_empty
27
+ end
28
+ end
29
+ end
6
30
 
7
31
  context 'collation methods acting in concert' do
8
32
  before(:each) do
@@ -22,6 +46,8 @@ describe AggtiveRecord do
22
46
  expect(MusicRecord.overall.count).to eq 4
23
47
  end
24
48
 
49
+
50
+
25
51
  it '#rate_per_week(:overall)' do
26
52
  old_time = MusicRecord.order('published_at').pluck(:published_at).first
27
53
  new_time = Time.now
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aggtive_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Nguyen