aggtive_record 0.1.5 → 0.2.0

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
- NzM2ZGIxNTQ3MjU2MmI0ZGQ2YmJmOTJjMjQxYjQxZTJmNGYwODI1ZQ==
4
+ M2M3MDM5ZjQxYTBjYjQ4NTU1ODBmZmEwMzgyMTUwZTcwNmU4ZTUwOA==
5
5
  data.tar.gz: !binary |-
6
- MmY0YmQ4ZDE1NGNkNTU2ZDZkNjFmNzg2YTczNjIyY2Q4NjIxZGFkNQ==
6
+ Y2VlZDg2MTU3NTBiZTk1OTNmNWE0NDM5Njk5YzkzMTFmYzA2ZDgwMw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MGZkMWFhMTFiMGMzODllNmY0ZDI5MmNmYWM4Zjg0NDA4MjRkZjQ4YmNhNzFm
10
- MmQ1ODRlMWVlMjg1ZDY0MmJjNDZmOTBiMDRmMjNmMzBiZDYxOTc4NjFlNWM0
11
- M2JhMWM3NDJhN2IxMWNkOWU5ZTNmMTJlYTg2MjU0YWFiMTZjYzg=
9
+ NmQxZGFhMmY1ZWU5Y2IyMmJlNDViOTVkNDM0ZGFmMmIyMzliNDhmOTczMGMz
10
+ Nzc3ZmNjNzVkMjAzMmMxODlhNWFiMzdjYzJjOWRjMjZlZWYxYzE5NjZkZGQ3
11
+ ZWQyZGViMzAyZTE3Yzc2MDhlMjY4ZDQxNjg0YjZjNmNkMDcwZDc=
12
12
  data.tar.gz: !binary |-
13
- MGQyOWZhNWMzMjgwMjVmNGM1N2RkMGJhZDA0NjI1MWEyZjNiNzk4YjJiNTNm
14
- ZjRiMzNjNjlhZmYyMWUzODcwNTA3OWYwNzRhNzhlZWQ1NzhlMTZhMzE3Y2I1
15
- MmI5Mzk2NWI0MzM2NGJkZmJhNGYyODkyOTNmNDAwNTlkODNjMjU=
13
+ ZTM5ZTdhYWQyYmFjMjU3YTY3YTQ2YWNhMDk5ZGY0OTYwMzkxYWQwNWM3YzYy
14
+ NTJkMTdmNzk1NzlkMTI2NmE0NmI4OGU3ODVkNGQ1NTBlODI0OTg1Njg3NzYz
15
+ YjBhZDdlYzM0ZjUxOGU2NWNjNGI2OTRiOWYzOWMxNzFhNmUzMDA=
data/Gemfile CHANGED
@@ -4,7 +4,7 @@ source "http://rubygems.org"
4
4
  group :development do
5
5
  gem "rspec", "~> 2.14.1"
6
6
  gem "bundler"
7
- gem "jeweler", "~> 1.8.4"
7
+ gem "jeweler"
8
8
  gem 'pry'
9
9
  gem 'database_cleaner', '~> 1.0.1'
10
10
  gem 'mysql2'
data/Gemfile.lock CHANGED
@@ -34,7 +34,7 @@ GEM
34
34
  highline (1.6.19)
35
35
  httpauth (0.2.0)
36
36
  i18n (0.6.5)
37
- jeweler (1.8.7)
37
+ jeweler (1.8.8)
38
38
  builder
39
39
  bundler (~> 1.0)
40
40
  git (>= 1.2.5)
@@ -47,7 +47,7 @@ GEM
47
47
  jwt (0.1.8)
48
48
  multi_json (>= 1.5)
49
49
  method_source (0.8.2)
50
- multi_json (1.8.0)
50
+ multi_json (1.8.1)
51
51
  multi_xml (0.5.5)
52
52
  multipart-post (1.2.0)
53
53
  mysql2 (0.3.13)
@@ -77,7 +77,7 @@ GEM
77
77
  rspec-mocks (2.14.3)
78
78
  slop (3.4.6)
79
79
  timecop (0.6.3)
80
- tzinfo (0.3.37)
80
+ tzinfo (0.3.38)
81
81
 
82
82
  PLATFORMS
83
83
  ruby
@@ -88,7 +88,7 @@ DEPENDENCIES
88
88
  bundler
89
89
  database_cleaner (~> 1.0.1)
90
90
  groupdate
91
- jeweler (~> 1.8.4)
91
+ jeweler
92
92
  mysql2
93
93
  pry
94
94
  rspec (~> 2.14.1)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.2.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "aggtive_record"
8
- s.version = "0.1.5"
8
+ s.version = "0.2.0"
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"]
12
- s.date = "2013-10-02"
12
+ s.date = "2013-10-11"
13
13
  s.description = "This is not even remotely finished or even started on. Please don't download."
14
14
  s.email = "dansonguyen@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -63,7 +63,7 @@ Gem::Specification.new do |s|
63
63
  s.add_runtime_dependency(%q<activesupport>, ["~> 3.2.14"])
64
64
  s.add_development_dependency(%q<rspec>, ["~> 2.14.1"])
65
65
  s.add_development_dependency(%q<bundler>, [">= 0"])
66
- s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
66
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
67
67
  s.add_development_dependency(%q<pry>, [">= 0"])
68
68
  s.add_development_dependency(%q<database_cleaner>, ["~> 1.0.1"])
69
69
  s.add_development_dependency(%q<mysql2>, [">= 0"])
@@ -74,7 +74,7 @@ Gem::Specification.new do |s|
74
74
  s.add_dependency(%q<activesupport>, ["~> 3.2.14"])
75
75
  s.add_dependency(%q<rspec>, ["~> 2.14.1"])
76
76
  s.add_dependency(%q<bundler>, [">= 0"])
77
- s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
77
+ s.add_dependency(%q<jeweler>, [">= 0"])
78
78
  s.add_dependency(%q<pry>, [">= 0"])
79
79
  s.add_dependency(%q<database_cleaner>, ["~> 1.0.1"])
80
80
  s.add_dependency(%q<mysql2>, [">= 0"])
@@ -86,7 +86,7 @@ Gem::Specification.new do |s|
86
86
  s.add_dependency(%q<activesupport>, ["~> 3.2.14"])
87
87
  s.add_dependency(%q<rspec>, ["~> 2.14.1"])
88
88
  s.add_dependency(%q<bundler>, [">= 0"])
89
- s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
89
+ s.add_dependency(%q<jeweler>, [">= 0"])
90
90
  s.add_dependency(%q<pry>, [">= 0"])
91
91
  s.add_dependency(%q<database_cleaner>, ["~> 1.0.1"])
92
92
  s.add_dependency(%q<mysql2>, [">= 0"])
@@ -17,12 +17,15 @@ module AggtiveRecord
17
17
  # tk: this may be unnecessary
18
18
  records = self.scoped.to_a
19
19
 
20
- time_period_secs = AggtiveRecord::Time.to_seconds(time_period)
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
24
  timespan_in_seconds ||= self.timespan_to_now(records)
22
25
 
23
26
 
24
27
 
25
- return records.size.to_f * time_period_secs / timespan_in_seconds
28
+ return records.size.to_f * time_period_in_secs / timespan_in_seconds
26
29
  end
27
30
 
28
31
  # defines rate_per_year, rate_per_hour
@@ -31,18 +34,16 @@ module AggtiveRecord
31
34
  AggtiveRecord::Time.periods.each do |period_name|
32
35
  foo_name = "rate_per_#{period_name}".to_sym
33
36
  # defining scope here, dynamically
34
- define_method foo_name do |*args|
35
-
36
-
37
- if args[0].present?
37
+ define_method foo_name do |*args|
38
+ if args[0].present? && args[0] !~ /^overall$/
38
39
  # i.e: #rate_per_month(:past_year)
39
- past_scope = args[0] # past_year
40
- raise ArgumentError, "Must be a scope with 'past_'" unless past_scope.to_s =~ /^past_/
40
+ past_scope = args[0] # past_year, :overall
41
+ raise ArgumentError, "Must be a scope with 'past_' or 'overall'" unless past_scope.to_s =~ /^past_/
41
42
 
42
43
  time_scoped_records = self.send( past_scope )
43
44
  past_time_span_name = past_scope.to_s.match(/past_(\w+)/)[1]
44
45
  past_period_in_seconds = AggtiveRecord::Time.to_seconds(past_time_span_name)
45
- else
46
+ else # overall or no argument
46
47
  time_scoped_records = scoped
47
48
  past_period_in_seconds = self.timespan_to_now(time_scoped_records)
48
49
  end
@@ -20,8 +20,6 @@ module AggtiveRecord
20
20
  send( groupdate_foo_name, self.datetime_attribute )
21
21
  }
22
22
  end
23
-
24
-
25
23
  end
26
24
 
27
25
 
@@ -11,6 +11,8 @@ module AggtiveRecord
11
11
 
12
12
  scope :past_time_periods, ->(num, period_name){ where("#{self.datetime_attribute} >= ?", num.send(period_name).send(:ago) ) }
13
13
 
14
+ # just include all records
15
+ scope :overall, ->(){ where("#{self.datetime_attribute} IS NOT ?", nil) }
14
16
 
15
17
  # singular time periods
16
18
  # e.g. scope :past_year, ->{ past_time_periods(1, :year)}
@@ -18,10 +18,23 @@ describe AggtiveRecord do
18
18
  expect(MusicRecord.past_14_days.count).to eq 1
19
19
  end
20
20
 
21
+ it '#overall' do
22
+ expect(MusicRecord.overall.count).to eq 4
23
+ end
24
+
25
+ it '#rate_per_week(:overall)' do
26
+ old_time = MusicRecord.order('published_at').pluck(:published_at).first
27
+ new_time = Time.now
28
+
29
+ expect(MusicRecord.rate_per_week(:overall)).to eq 4.0 * AggtiveRecord::Time.to_seconds(:week) / (new_time - old_time)
30
+ end
31
+
32
+
21
33
  it '#rate_per_week(:past_14_days)' do
22
34
  expect(MusicRecord.rate_per_week(:past_14_days)).to eq 0.5
23
35
  end
24
36
 
37
+
25
38
  it '#past_year' do
26
39
  expect(MusicRecord.past_year.count).to eq 3
27
40
  end
data/spec/spec_helper.rb CHANGED
@@ -47,6 +47,12 @@ DatabaseCleaner.strategy = :truncation
47
47
 
48
48
 
49
49
  RSpec.configure do |config|
50
+ config.filter_run_excluding skip: true
51
+ config.run_all_when_everything_filtered = true
52
+ config.filter_run :focus => true
53
+
54
+
55
+
50
56
  config.color_enabled = true
51
57
  config.tty = true
52
58
  config.formatter = :documentation # :progress, :html, :textmate
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aggtive_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Nguyen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-02 00:00:00.000000000 Z
11
+ date: 2013-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: groupdate
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: jeweler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - ! '>='
74
74
  - !ruby/object:Gem::Version
75
- version: 1.8.4
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - ! '>='
81
81
  - !ruby/object:Gem::Version
82
- version: 1.8.4
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: pry
85
85
  requirement: !ruby/object:Gem::Requirement