tardis 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fd81323814d01d31fb82be8ac90979f8512f408d
4
+ data.tar.gz: 6d5f1b7ec03662eccf3368cfb1c0ba377f56e8af
5
+ SHA512:
6
+ metadata.gz: 44432b5b0684e8e51f00306d382dff1a792c2babbcee1f94b862b40566426c0b59f83dc95dbd806ab81cf6160d1e85cf242514c50ae6b3ec565ab981b5f0ac00
7
+ data.tar.gz: ce6359ce3908d310c73520f62d7f7e3ed2370f674d03a0c2f59d16bcb8823e001fc8b06bb7145c66a95944f9767d78292e8e94030061d1ba0140ccad1e6fe196
@@ -0,0 +1,6 @@
1
+ module Tardis
2
+ require_relative "tardis/version"
3
+ require_relative "tardis/moment"
4
+ end
5
+
6
+ require_relative "tardis/main"
@@ -0,0 +1,14 @@
1
+ class Numeric
2
+ include(Tardis::Moment::Downscale)
3
+ include(Tardis::Moment::Upscale)
4
+ end
5
+
6
+ class Time
7
+ include(Tardis::Moment)
8
+ include(Tardis::Moment::Traversal)
9
+ end
10
+
11
+ class Date
12
+ include(Tardis::Moment)
13
+ include(Tardis::Moment::Traversal)
14
+ end
@@ -0,0 +1,17 @@
1
+ # Tardis::Time is the module where all time based methods, classes, and modules
2
+ # are defined. Anything that has to do with the second unit of measurement goes
3
+ # into Tardis::Time.
4
+ module Tardis
5
+ module Moment
6
+ # The units of time, based in seconds
7
+ SECOND = 1
8
+ MINUTE = SECOND * 60
9
+ HOUR = MINUTE * 60
10
+ DAY = HOUR * 24
11
+ WEEK = DAY * 7
12
+
13
+ require_relative "moment/upscale"
14
+ require_relative "moment/downscale"
15
+ require_relative "moment/traversal"
16
+ end
17
+ end
@@ -0,0 +1,35 @@
1
+ module Tardis
2
+ module Moment
3
+ module Downscale
4
+ def to_seconds
5
+ downscale_to(Tardis::Moment::SECOND)
6
+ end
7
+ alias_method :in_seconds, :to_seconds
8
+
9
+ def to_minutes
10
+ downscale_to(Tardis::Moment::MINUTE)
11
+ end
12
+ alias_method :in_minutes, :to_minutes
13
+
14
+ def to_hours
15
+ downscale_to(Tardis::Moment::HOUR)
16
+ end
17
+ alias_method :in_hours, :to_hours
18
+
19
+ def to_days
20
+ downscale_to(Tardis::Moment::DAY)
21
+ end
22
+ alias_method :in_days, :to_days
23
+
24
+ def to_weeks
25
+ downscale_to(Tardis::Moment::WEEK)
26
+ end
27
+ alias_method :in_weeks, :to_weeks
28
+
29
+ def downscale_to(unit)
30
+ self.to_f / unit.to_f
31
+ end
32
+ private :downscale_to
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,93 @@
1
+ module Tardis
2
+ module Moment
3
+ module Traversal
4
+ # example: time_left = next_birthday.from Date.yesterday
5
+ # anatomy: [Time|Date].from([Time|Date]) => Integer
6
+ # description: |
7
+ # Called on a Time or Date object and given a Time or Date object.
8
+ # Returns an Integer, representing a number of seconds between the
9
+ # object called on (a time in the future) and the object given (a
10
+ # time in the past).
11
+ def from(timestamp)
12
+ # Transform the time/date object (self), which represents the
13
+ # starting point, to an integer.
14
+ beginning = self.to_i
15
+
16
+ # Transform the time/date object (an argument), which represents
17
+ # the point in the
18
+ ending = timestamp.to_i
19
+
20
+ # Subtract the end period from the start period which will
21
+ # return the total amount of time in seconds from the
22
+ # start the end.
23
+ beginning - ending
24
+ end
25
+
26
+ # example: @account.created_at.to Date.today
27
+ # anatomy: [Time|Date].to([Time|Date]) => Integer
28
+ # description: |
29
+ # Called on a Time or Date object and given a Time or Date object.
30
+ # Returns an Integer, representing a number of seconds between the
31
+ # object called on (a time in the past) and the object given (a
32
+ # time in the future).
33
+ def to(timestamp)
34
+ # Transform the time/date object (self), which represents the
35
+ # starting point, to an integer.
36
+ beginning = timestamp.to_i
37
+
38
+ # Transform the time/date object (an argument), which represents
39
+ # the point in the
40
+ ending = self.to_i
41
+
42
+ # Subtract the end period from the start period which will
43
+ # return the total amount of time in seconds from the
44
+ # start the end.
45
+ beginning - ending
46
+ end
47
+
48
+ # example: time_left = next_birthday.from_now
49
+ # anatomy: [Time|Date].from_now => Integer
50
+ # description: |
51
+ # Called on a Time or Date object and returns an Integer,
52
+ # representing a number of seconds between the object
53
+ # called on (a time in the future) and now in time.
54
+ def from_now
55
+ # Call the .from() method with self as the starting point and
56
+ # Time.new as the end
57
+ self.from(Time.new)
58
+ end
59
+
60
+ # example: @account.created_at.to_now
61
+ # anatomy: [Time|Date].to_now => Integer
62
+ # description: |
63
+ # Called on a Time or Date object and returns an Integer,
64
+ # representing a number of seconds between the object
65
+ # called on (a time in the past) and now in time.
66
+ def to_now
67
+ # Call the .to() method with self as the starting point and
68
+ # Time.new as the end
69
+ self.to(Time.new)
70
+ end
71
+
72
+ # example: 5.days.ago
73
+ # anatomy: [Integer].ago => Time
74
+ # description: |
75
+ # Called on an Integer object and returns an Time object, which
76
+ # represents the point in time before the given amount of seconds.
77
+ def ago
78
+ # Subtract the Integer from Time.new
79
+ Time.new - self
80
+ end
81
+
82
+ # example: 5.days.later
83
+ # anatomy: [Integer].later => Time
84
+ # description: |
85
+ # Called on an Integer object and returns an Time object, which
86
+ # represents the point in time after the given amount of seconds.
87
+ def later
88
+ # Add the Integer to Time.new
89
+ Time.new + self
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,35 @@
1
+ module Tardis
2
+ module Moment
3
+ module Upscale
4
+ def second
5
+ upscale_to(Tardis::Moment::SECOND)
6
+ end
7
+ alias_method :seconds, :second
8
+
9
+ def minute
10
+ upscale_to(Tardis::Moment::MINUTE)
11
+ end
12
+ alias_method :minutes, :minute
13
+
14
+ def hour
15
+ upscale_to(Tardis::Moment::HOUR)
16
+ end
17
+ alias_method :hours, :hour
18
+
19
+ def day
20
+ upscale_to(Tardis::Moment::DAY)
21
+ end
22
+ alias_method :days, :day
23
+
24
+ def week
25
+ upscale_to(Tardis::Moment::WEEK)
26
+ end
27
+ alias_method :weeks, :week
28
+
29
+ def upscale_to(unit)
30
+ self * unit
31
+ end
32
+ private :upscale_to
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module Tardis
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,49 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Tardis::Moment do
4
+ let(:described_class) { Class.new { include Tardis::Moment } }
5
+ let(:minute) { described_class.const_get("MINUTE") }
6
+ let(:hour) { described_class.const_get("HOUR") }
7
+ let(:day) { described_class.const_get("DAY") }
8
+ let(:week) { described_class.const_get("WEEK") }
9
+
10
+ describe Tardis::Moment::SECOND do
11
+ let(:second) { described_class.const_get("SECOND") }
12
+
13
+ it "is the base unit" do
14
+ expect(second).to eq(1)
15
+ end
16
+ end
17
+
18
+ describe Tardis::Moment::MINUTE do
19
+ let(:minute) { described_class.const_get("MINUTE") }
20
+
21
+ it "is the correct value in seconds" do
22
+ expect(minute).to eq(60)
23
+ end
24
+ end
25
+
26
+ describe Tardis::Moment::HOUR do
27
+ let(:hour) { described_class.const_get("HOUR") }
28
+
29
+ it "is the correct value in seconds" do
30
+ expect(hour).to eq(3_600)
31
+ end
32
+ end
33
+
34
+ describe Tardis::Moment::DAY do
35
+ let(:day) { described_class.const_get("DAY") }
36
+
37
+ it "is the correct value in seconds" do
38
+ expect(day).to eq(86_400)
39
+ end
40
+ end
41
+
42
+ describe Tardis::Moment::WEEK do
43
+ let(:week) { described_class.const_get("WEEK") }
44
+
45
+ it "is the correct value in seconds" do
46
+ expect(week).to eq(604_800)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,67 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Tardis::Moment::Downscale do
4
+ before(:each) do
5
+ Numeric.include(Tardis::Moment::Downscale)
6
+ end
7
+
8
+ describe "#to_seconds" do
9
+ it "returns number of seconds" do
10
+ expect(1.to_seconds).to eq(1)
11
+ end
12
+ end
13
+
14
+ describe "#as_seconds" do
15
+ it "returns number of seconds" do
16
+ expect(2.in_seconds).to eq(2)
17
+ end
18
+ end
19
+
20
+ describe "#to_minutes" do
21
+ it "returns number of minutes" do
22
+ expect(60.to_minutes).to eq(1)
23
+ end
24
+ end
25
+
26
+ describe "#as_minutes" do
27
+ it "returns number of minutes" do
28
+ expect(120.in_minutes).to eq(2)
29
+ end
30
+ end
31
+
32
+ describe "#hour" do
33
+ it "returns number of hours" do
34
+ expect(3_600.to_hours).to eq(1)
35
+ end
36
+ end
37
+
38
+ describe "#hours" do
39
+ it "returns number of hours" do
40
+ expect(7_200.in_hours).to eq(2)
41
+ end
42
+ end
43
+
44
+ describe "#day" do
45
+ it "returns number of days" do
46
+ expect(86_400.to_days).to eq(1)
47
+ end
48
+ end
49
+
50
+ describe "#days" do
51
+ it "returns number of days" do
52
+ expect(172_800.in_days).to eq(2)
53
+ end
54
+ end
55
+
56
+ describe "#week" do
57
+ it "returns number of weeks" do
58
+ expect(604_800.to_weeks).to eq(1)
59
+ end
60
+ end
61
+
62
+ describe "#weeks" do
63
+ it "returns number of weeks" do
64
+ expect(1_209_600.in_weeks).to eq(2)
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,7 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Tardis::Moment::Traversal do
4
+ before(:each) do
5
+ Time.include(Tardis::Moment::Traversal)
6
+ end
7
+ end
@@ -0,0 +1,67 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Tardis::Moment::Upscale do
4
+ before(:each) do
5
+ Numeric.include(Tardis::Moment::Upscale)
6
+ end
7
+
8
+ describe "#second" do
9
+ it "returns seconds, based on the number given in seconds" do
10
+ expect(1.second).to eq(1)
11
+ end
12
+ end
13
+
14
+ describe "#seconds" do
15
+ it "returns seconds, based on the number given in seconds" do
16
+ expect(2.seconds).to eq(2)
17
+ end
18
+ end
19
+
20
+ describe "#minute" do
21
+ it "returns seconds, based on the number given in minutes" do
22
+ expect(1.minute).to eq(60)
23
+ end
24
+ end
25
+
26
+ describe "#minutes" do
27
+ it "returns seconds, based on the number given in minutes" do
28
+ expect(2.minutes).to eq(120)
29
+ end
30
+ end
31
+
32
+ describe "#hour" do
33
+ it "returns seconds, based on the number given in hours" do
34
+ expect(1.hour).to eq(3_600)
35
+ end
36
+ end
37
+
38
+ describe "#hours" do
39
+ it "returns seconds, based on the number given in hours" do
40
+ expect(2.hours).to eq(7_200)
41
+ end
42
+ end
43
+
44
+ describe "#day" do
45
+ it "returns seconds, based on the number given in days" do
46
+ expect(1.day).to eq(86_400)
47
+ end
48
+ end
49
+
50
+ describe "#days" do
51
+ it "returns seconds, based on the number given in days" do
52
+ expect(2.days).to eq(172_800)
53
+ end
54
+ end
55
+
56
+ describe "#week" do
57
+ it "returns seconds, based on the number given in weeks" do
58
+ expect(1.week).to eq(604_800)
59
+ end
60
+ end
61
+
62
+ describe "#weeks" do
63
+ it "returns seconds, based on the number given in weeks" do
64
+ expect(2.weeks).to eq(1_209_600)
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,7 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Tardis::VERSION do
4
+ it "should be a string" do
5
+ expect(Tardis::VERSION).to be_kind_of(String)
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Tardis do
4
+
5
+ end
@@ -0,0 +1,6 @@
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
3
+
4
+ require "pry"
5
+ require "rspec"
6
+ require "tardis"
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tardis
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kurtis Rainbolt-Greene
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.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: '10.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-doc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: codeclimate-test-reporter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.4'
97
+ description: A library for managing units of time and traversal of time.
98
+ email:
99
+ - me@kurtisrainboltgreene.name
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - lib/tardis.rb
105
+ - lib/tardis/main.rb
106
+ - lib/tardis/moment.rb
107
+ - lib/tardis/moment/downscale.rb
108
+ - lib/tardis/moment/traversal.rb
109
+ - lib/tardis/moment/upscale.rb
110
+ - lib/tardis/version.rb
111
+ - spec/lib/tardis/moment_spec.rb
112
+ - spec/lib/tardis/time/downscale_spec.rb
113
+ - spec/lib/tardis/time/traversal_spec.rb
114
+ - spec/lib/tardis/time/upscale_spec.rb
115
+ - spec/lib/tardis/version_spec.rb
116
+ - spec/lib/tardis_spec.rb
117
+ - spec/spec_helper.rb
118
+ homepage: http://krainboltgreene.github.io/tardis.gem
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.4.6
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: A library for managing units of time and traversal of time.
142
+ test_files:
143
+ - spec/lib/tardis/moment_spec.rb
144
+ - spec/lib/tardis/time/downscale_spec.rb
145
+ - spec/lib/tardis/time/traversal_spec.rb
146
+ - spec/lib/tardis/time/upscale_spec.rb
147
+ - spec/lib/tardis/version_spec.rb
148
+ - spec/lib/tardis_spec.rb
149
+ - spec/spec_helper.rb
150
+ has_rdoc: