chronological 0.0.1
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.
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/chronological/version.rb +3 -0
- data/lib/chronological.rb +96 -0
- metadata +53 -0
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Jeff Felchner
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Chronological
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'chronological'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install chronological
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module Chronological
|
2
|
+
module ClassMethods
|
3
|
+
###
|
4
|
+
# Scopes
|
5
|
+
#
|
6
|
+
def by_date
|
7
|
+
order "#{table_name}.started_at_utc ASC, #{table_name}.ended_at_utc ASC"
|
8
|
+
end
|
9
|
+
|
10
|
+
def by_date_reversed
|
11
|
+
order "#{table_name}.started_at_utc DESC, #{table_name}.ended_at_utc DESC"
|
12
|
+
end
|
13
|
+
|
14
|
+
def expired
|
15
|
+
where('ended_at_utc < :now', :now => Time.now.utc)
|
16
|
+
end
|
17
|
+
|
18
|
+
def current
|
19
|
+
where('ended_at_utc > :now', :now => Time.now.utc)
|
20
|
+
end
|
21
|
+
|
22
|
+
def in_progress
|
23
|
+
where('started_at_utc <= :now AND ended_at_utc > :now', :now => Time.now.utc)
|
24
|
+
end
|
25
|
+
|
26
|
+
alias active in_progress
|
27
|
+
|
28
|
+
def in_progress?
|
29
|
+
in_progress.any?
|
30
|
+
end
|
31
|
+
|
32
|
+
alias active? in_progress?
|
33
|
+
|
34
|
+
def started
|
35
|
+
where("started_at_utc <= :now", :now => Time.now.utc)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.included(base)
|
40
|
+
base.extend ClassMethods
|
41
|
+
end
|
42
|
+
|
43
|
+
###
|
44
|
+
# Aliases
|
45
|
+
#
|
46
|
+
# Aliasing date methods to make code more readable
|
47
|
+
|
48
|
+
alias_attribute :starts_at, :started_at
|
49
|
+
alias_attribute :starting_at, :started_at
|
50
|
+
alias_attribute :ends_at, :ended_at
|
51
|
+
alias_attribute :ending_at, :ended_at
|
52
|
+
alias_attribute :starts_at_utc, :started_at_utc
|
53
|
+
alias_attribute :starting_at_utc, :started_at_utc
|
54
|
+
alias_attribute :ends_at_utc, :ended_at_utc
|
55
|
+
alias_attribute :ending_at_utc, :ended_at_utc
|
56
|
+
|
57
|
+
def started_at_date
|
58
|
+
return nil unless started_at.respond_to? :to_date
|
59
|
+
|
60
|
+
started_at.to_date
|
61
|
+
end
|
62
|
+
|
63
|
+
def ended_at_date
|
64
|
+
return nil unless ended_at.respond_to? :to_date
|
65
|
+
|
66
|
+
ended_at.to_date
|
67
|
+
end
|
68
|
+
|
69
|
+
def in_progress?
|
70
|
+
return false unless scheduled?
|
71
|
+
|
72
|
+
self.started_at.past? && self.ending_at.future?
|
73
|
+
end
|
74
|
+
|
75
|
+
alias active? in_progress?
|
76
|
+
|
77
|
+
def inactive?
|
78
|
+
!active?
|
79
|
+
end
|
80
|
+
|
81
|
+
def scheduled?
|
82
|
+
started_at.present? || ended_at.present? || time_zone.present?
|
83
|
+
end
|
84
|
+
|
85
|
+
def duration
|
86
|
+
hours = (duration_in_minutes / 60).to_int
|
87
|
+
minutes = (duration_in_minutes % 60).to_int
|
88
|
+
|
89
|
+
{ :hours => hours, :minutes => minutes }
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
def duration_in_minutes
|
94
|
+
@duration_in_minutes ||= (ended_at - started_at) / 60
|
95
|
+
end
|
96
|
+
end
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chronological
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- jfelchner
|
9
|
+
- m5rk
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-10-02 00:00:00.000000000 Z
|
14
|
+
dependencies: []
|
15
|
+
description: ''
|
16
|
+
email: support@chirrpy.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files:
|
20
|
+
- README.md
|
21
|
+
- LICENSE
|
22
|
+
files:
|
23
|
+
- lib/chronological/version.rb
|
24
|
+
- lib/chronological.rb
|
25
|
+
- Rakefile
|
26
|
+
- README.md
|
27
|
+
- LICENSE
|
28
|
+
homepage: https://github.com/chirrpy/chronological
|
29
|
+
licenses: []
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options:
|
32
|
+
- --charset = UTF-8
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubyforge_project: chronological
|
49
|
+
rubygems_version: 1.8.24
|
50
|
+
signing_key:
|
51
|
+
specification_version: 3
|
52
|
+
summary: Easy Accessors for ActiveModel Objects
|
53
|
+
test_files: []
|