time-lord 0.2.5 → 1.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.
Files changed (45) hide show
  1. data/.gitignore +34 -4
  2. data/.rvmrc +38 -34
  3. data/.travis.yml +5 -0
  4. data/COPYRIGHT +19 -16
  5. data/README.md +46 -22
  6. data/Rakefile +30 -1
  7. data/lib/time-lord.rb +6 -81
  8. data/lib/time-lord/extensions/integer.rb +16 -0
  9. data/lib/time-lord/extensions/time.rb +5 -0
  10. data/lib/time-lord/period.rb +54 -0
  11. data/lib/time-lord/scale.rb +49 -0
  12. data/lib/time-lord/time.rb +13 -0
  13. data/lib/time-lord/units.rb +11 -0
  14. data/lib/time-lord/units/business.rb +6 -0
  15. data/lib/time-lord/units/long.rb +11 -0
  16. data/lib/time-lord/units/special.rb +8 -0
  17. data/lib/time-lord/version.rb +1 -1
  18. data/test/helper.rb +1 -3
  19. data/test/lib/time-lord/extentions/integer_test.rb +24 -0
  20. data/test/lib/time-lord/extentions/time_test.rb +30 -0
  21. data/test/lib/time-lord/period_test.rb +50 -0
  22. data/test/lib/time-lord/scale_test.rb +34 -0
  23. data/test/lib/time-lord/time_test.rb +32 -0
  24. data/test/lib/time-lord_test.rb +12 -0
  25. data/time-lord.gemspec +22 -18
  26. metadata +87 -30
  27. data/.yardoc/checksums +0 -2
  28. data/.yardoc/objects/root.dat +0 -0
  29. data/.yardoc/proxy_types +0 -2
  30. data/doc/Time.html +0 -290
  31. data/doc/TimeLord.html +0 -93
  32. data/doc/_index.html +0 -100
  33. data/doc/class_list.html +0 -36
  34. data/doc/css/common.css +0 -1
  35. data/doc/css/full_list.css +0 -53
  36. data/doc/css/style.css +0 -318
  37. data/doc/file.README.html +0 -104
  38. data/doc/file_list.html +0 -38
  39. data/doc/frames.html +0 -13
  40. data/doc/index.html +0 -104
  41. data/doc/js/app.js +0 -203
  42. data/doc/js/full_list.js +0 -149
  43. data/doc/js/jquery.js +0 -16
  44. data/doc/method_list.html +0 -43
  45. data/doc/top-level-namespace.html +0 -90
@@ -0,0 +1,49 @@
1
+ module TimeLord
2
+ class Scale
3
+ include Units
4
+
5
+ attr_accessor :absolute
6
+
7
+ def initialize(absolute)
8
+ self.absolute = absolute
9
+ end
10
+
11
+ def to_value
12
+ timemap.first
13
+ end
14
+
15
+ def to_unit
16
+ timemap.last
17
+ end
18
+
19
+ private
20
+
21
+ def timemap
22
+ case absolute
23
+ when SECOND...MINUTE then [absolute, pluralized_word("second", plurality?(absolute)) || "second"]
24
+ when MINUTE...HOUR then as(MINUTE, "minute")
25
+ when HOUR...DAY then as(HOUR, "hour")
26
+ when DAY...WEEK then as(DAY, "day")
27
+ when WEEK...MONTH then as(WEEK, "week")
28
+ when MONTH...YEAR then as(MONTH, "month")
29
+ else as(YEAR, "year")
30
+ end
31
+ end
32
+
33
+ def as(unit, word)
34
+ [count(unit), pluralized_word(word, plurality?(count(unit))) || word]
35
+ end
36
+
37
+ def count(unit)
38
+ absolute / unit
39
+ end
40
+
41
+ def pluralized_word(word, plural)
42
+ word += "s" if plural
43
+ end
44
+
45
+ def plurality?(count)
46
+ count > 1 || count.zero?
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,13 @@
1
+ module TimeLord
2
+ class Time
3
+ attr_accessor :moment
4
+
5
+ def initialize(moment)
6
+ self.moment = moment
7
+ end
8
+
9
+ def period
10
+ Period.new(moment, ::Time.now)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module TimeLord
2
+ module Units
3
+ SECOND = 1
4
+ MINUTE = SECOND * 60
5
+ HOUR = MINUTE * 60
6
+ DAY = HOUR * 24
7
+ WEEK = DAY * 7
8
+ MONTH = WEEK * 4
9
+ YEAR = MONTH * 12
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ module TimeLord
2
+ module Units
3
+ # Business units of time
4
+ QUARTER = MONTH * 3
5
+ end
6
+ end
@@ -0,0 +1,11 @@
1
+ module TimeLord
2
+ module Units
3
+ # Very long units of time
4
+ FORTNIGHT = WEEK * 2
5
+ OLYMPIAD = YEAR * 4
6
+ LUSTRUM = YEAR * 5
7
+ INDICTION = YEAR * 15
8
+ JUBILEE = DECADE * 5
9
+ EON = 1.0/0
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ module TimeLord
2
+ module Units
3
+ # Very special units of time
4
+ DECADE = YEAR * 10
5
+ CENTURY = DECADE * 10
6
+ MILLENNIUM = CENTURY * 10
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module TimeLord
2
- VERSION = "0.2.5"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -1,3 +1 @@
1
- require 'minitest/spec'
2
- require 'minitest/autorun'
3
- require File.expand_path(File.dirname(__FILE__) + '/../lib/time-lord.rb')
1
+ require 'time-lord'
@@ -0,0 +1,24 @@
1
+ require 'minitest/autorun'
2
+ require 'helper'
3
+
4
+ class TestTimeLordExtentionsInteger < MiniTest::Unit::TestCase
5
+ def test_minutes
6
+ expected = 1
7
+ actual = 1.second
8
+ assert_equal(expected, actual)
9
+
10
+ expected = 2
11
+ actual = 2.seconds
12
+ assert_equal(expected, actual)
13
+ end
14
+
15
+ def test_minutes
16
+ expected = 60
17
+ actual = 1.minute
18
+ assert_equal(expected, actual)
19
+
20
+ expected = 120
21
+ actual = 2.minutes
22
+ assert_equal(expected, actual)
23
+ end
24
+ end
@@ -0,0 +1,30 @@
1
+ require 'minitest/autorun'
2
+ require_relative '../../../helper'
3
+
4
+ class TestTimeLordExtentionsTime < MiniTest::Unit::TestCase
5
+ def setup
6
+ @timestamp = Time.now
7
+ end
8
+
9
+ def oldstamp(minus)
10
+ @timestamp - minus
11
+ end
12
+
13
+ def test_ago_in_words_on_time
14
+ expected = "3 days ago"
15
+ actual = oldstamp(3.days).ago.in_words
16
+ assert_equal(expected, actual)
17
+ end
18
+
19
+ def test_ago_in_words_about
20
+ expected = "1 hour ago"
21
+ actual = oldstamp(100.minutes).ago.in_words
22
+ assert_equal(expected, actual)
23
+ end
24
+
25
+ def test_ago_in_words_less_than_minute
26
+ expected = "15 seconds ago"
27
+ actual = oldstamp(15.seconds).ago.in_words
28
+ assert_equal(expected, actual)
29
+ end
30
+ end
@@ -0,0 +1,50 @@
1
+ require 'minitest/autorun'
2
+ require 'helper'
3
+
4
+ class TestTimeLordPeriod < MiniTest::Unit::TestCase
5
+ def setup
6
+ @timestamp = Time.now
7
+ end
8
+
9
+ def test_to_i_positive
10
+ expected = -100
11
+ actual = TimeLord::Period.new(@timestamp - 100, @timestamp).difference
12
+ assert_equal(expected, actual)
13
+ end
14
+
15
+ def test_to_i_negative
16
+ expected = 100
17
+ actual = TimeLord::Period.new(@timestamp + 100, @timestamp).difference
18
+ assert_equal(expected, actual)
19
+ end
20
+
21
+ def test_in_words_second
22
+ expected = "1 second ago"
23
+ actual = 1.second.ago.in_words
24
+ assert_equal(expected, actual)
25
+ end
26
+
27
+ def test_in_words_plural
28
+ expected = "2 years ago"
29
+ actual = 2.years.ago.in_words
30
+ assert_equal(expected, actual)
31
+ end
32
+
33
+ def test_in_words_past_year
34
+ expected = "1 year ago"
35
+ actual = 1.year.ago.in_words
36
+ assert_equal(expected, actual)
37
+ end
38
+
39
+ def test_in_words_future_year
40
+ expected = "1 year from now"
41
+ actual = 1.year.from_now.in_words
42
+ assert_equal(expected, actual)
43
+ end
44
+
45
+ def test_math
46
+ expected = Time.now - 2.days
47
+ actual = 2.days.ago.to_time
48
+ assert_equal(expected.to_i, actual.to_i)
49
+ end
50
+ end
@@ -0,0 +1,34 @@
1
+ require 'minitest/autorun'
2
+ require 'helper'
3
+
4
+ class TestTimeLordScale < MiniTest::Unit::TestCase
5
+ def test_to_value_single
6
+ expected = 1
7
+ actual = TimeLord::Scale.new(3600).to_value
8
+ assert_equal(expected, actual)
9
+ end
10
+
11
+ def test_to_value_multiple
12
+ expected = 2
13
+ actual = TimeLord::Scale.new(7200).to_value
14
+ assert_equal(expected, actual)
15
+ end
16
+
17
+ def test_to_unit_second_single
18
+ expected = "second"
19
+ actual = TimeLord::Scale.new(1).to_unit
20
+ assert_equal(expected, actual)
21
+ end
22
+
23
+ def test_to_unit_single
24
+ expected = "hour"
25
+ actual = TimeLord::Scale.new(3600).to_unit
26
+ assert_equal(expected, actual)
27
+ end
28
+
29
+ def test_to_unit_multiple
30
+ expected = "hours"
31
+ actual = TimeLord::Scale.new(7200).to_unit
32
+ assert_equal(expected, actual)
33
+ end
34
+ end
@@ -0,0 +1,32 @@
1
+ require 'minitest/autorun'
2
+ require 'helper'
3
+
4
+ class TestTimeLordTime < MiniTest::Unit::TestCase
5
+ def setup
6
+ @timestamp = Time.now
7
+ end
8
+
9
+ def test_to_words_past_seconds
10
+ expected = "50 seconds ago"
11
+ actual = TimeLord::Time.new(@timestamp - 50).period.to_words
12
+ assert_equal(expected, actual)
13
+ end
14
+
15
+ def test_to_words_singular
16
+ expected = "1 minute ago"
17
+ actual = TimeLord::Time.new(@timestamp - 60).period.to_words
18
+ assert_equal(expected, actual)
19
+ end
20
+
21
+ def test_to_words_future_days
22
+ expected = "2 days ago"
23
+ actual = TimeLord::Time.new(@timestamp - 172800).period.to_words
24
+ assert_equal(expected, actual)
25
+ end
26
+
27
+ def test_to_words_future_days
28
+ expected = "2 days from now"
29
+ actual = TimeLord::Time.new(@timestamp + 172800).period.to_words
30
+ assert_equal(expected, actual)
31
+ end
32
+ end
@@ -0,0 +1,12 @@
1
+ require 'minitest/autorun'
2
+ require 'helper'
3
+
4
+ class TestTimeLord < MiniTest::Unit::TestCase
5
+ def test_that_things_work
6
+ assert true
7
+ end
8
+
9
+ def test_that_namespace_defined
10
+ assert(defined?(TimeLord))
11
+ end
12
+ end
@@ -1,22 +1,26 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "time-lord/version"
1
+ # encoding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'time-lord/version'
4
5
 
5
- Gem::Specification.new do |s|
6
- s.name = "time-lord"
7
- s.version = TimeLord::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ["Kurtis Rainbolt-Greene","Simon Hørup Eskildsen"]
10
- s.email = ["kurtisrainboltgreene@gmail.com","sirup@sirupsen.com"]
11
- s.homepage = "http://github.com/krainboltgreene/time-lord#README"
12
- s.summary = %q{Adding various bonuses to the Time class.}
13
- s.description = %q{This is a gem that adds a ton of extras to the Time class.}
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "time-lord"
8
+ gem.version = TimeLord::VERSION
9
+ gem.authors = ["Kurtis Rainbolt-Greene", "Simon Hørup Eskildsen"]
10
+ gem.email = ["me@kurtisrainboltgreene.name","sirup@sirupsen.com"]
11
+ gem.summary = %q{Managing concepts of time and space in Ruby}
12
+ gem.description = gem.summary
13
+ gem.homepage = "http://krainboltgreene.github.com/time-lord"
14
14
 
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
15
19
 
16
- s.files = `git ls-files`.split("\n")
17
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
- s.require_paths = ["lib"]
20
-
21
- s.add_development_dependency "rake"
20
+ gem.add_development_dependency 'rake'
21
+ gem.add_development_dependency 'yard'
22
+ gem.add_development_dependency 'kramdown'
23
+ gem.add_development_dependency 'pry'
24
+ # gem.add_runtime_dependency 'gemname', '~> 1.0'
25
+ # gem.add_development_dependency 'gemname', '~> 1.0'
22
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time-lord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-11-30 00:00:00.000000000 Z
13
+ date: 2013-03-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
17
- requirement: &2152296180 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,63 @@ dependencies:
22
22
  version: '0'
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *2152296180
26
- description: This is a gem that adds a ton of extras to the Time class.
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: yard
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: kramdown
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: pry
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ description: Managing concepts of time and space in Ruby
27
80
  email:
28
- - kurtisrainboltgreene@gmail.com
81
+ - me@kurtisrainboltgreene.name
29
82
  - sirup@sirupsen.com
30
83
  executables: []
31
84
  extensions: []
@@ -33,35 +86,32 @@ extra_rdoc_files: []
33
86
  files:
34
87
  - .gitignore
35
88
  - .rvmrc
36
- - .yardoc/checksums
37
- - .yardoc/objects/root.dat
38
- - .yardoc/proxy_types
89
+ - .travis.yml
39
90
  - COPYRIGHT
40
91
  - Gemfile
41
92
  - README.md
42
93
  - Rakefile
43
- - doc/Time.html
44
- - doc/TimeLord.html
45
- - doc/_index.html
46
- - doc/class_list.html
47
- - doc/css/common.css
48
- - doc/css/full_list.css
49
- - doc/css/style.css
50
- - doc/file.README.html
51
- - doc/file_list.html
52
- - doc/frames.html
53
- - doc/index.html
54
- - doc/js/app.js
55
- - doc/js/full_list.js
56
- - doc/js/jquery.js
57
- - doc/method_list.html
58
- - doc/top-level-namespace.html
59
94
  - lib/time-lord.rb
95
+ - lib/time-lord/extensions/integer.rb
96
+ - lib/time-lord/extensions/time.rb
97
+ - lib/time-lord/period.rb
98
+ - lib/time-lord/scale.rb
99
+ - lib/time-lord/time.rb
100
+ - lib/time-lord/units.rb
101
+ - lib/time-lord/units/business.rb
102
+ - lib/time-lord/units/long.rb
103
+ - lib/time-lord/units/special.rb
60
104
  - lib/time-lord/version.rb
61
105
  - test/base.rb
62
106
  - test/helper.rb
107
+ - test/lib/time-lord/extentions/integer_test.rb
108
+ - test/lib/time-lord/extentions/time_test.rb
109
+ - test/lib/time-lord/period_test.rb
110
+ - test/lib/time-lord/scale_test.rb
111
+ - test/lib/time-lord/time_test.rb
112
+ - test/lib/time-lord_test.rb
63
113
  - time-lord.gemspec
64
- homepage: http://github.com/krainboltgreene/time-lord#README
114
+ homepage: http://krainboltgreene.github.com/time-lord
65
115
  licenses: []
66
116
  post_install_message:
67
117
  rdoc_options: []
@@ -75,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
125
  version: '0'
76
126
  segments:
77
127
  - 0
78
- hash: 504416042286362366
128
+ hash: 4317906458268921176
79
129
  required_rubygems_version: !ruby/object:Gem::Requirement
80
130
  none: false
81
131
  requirements:
@@ -84,13 +134,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
134
  version: '0'
85
135
  segments:
86
136
  - 0
87
- hash: 504416042286362366
137
+ hash: 4317906458268921176
88
138
  requirements: []
89
139
  rubyforge_project:
90
- rubygems_version: 1.8.10
140
+ rubygems_version: 1.8.25
91
141
  signing_key:
92
142
  specification_version: 3
93
- summary: Adding various bonuses to the Time class.
143
+ summary: Managing concepts of time and space in Ruby
94
144
  test_files:
95
145
  - test/base.rb
96
146
  - test/helper.rb
147
+ - test/lib/time-lord/extentions/integer_test.rb
148
+ - test/lib/time-lord/extentions/time_test.rb
149
+ - test/lib/time-lord/period_test.rb
150
+ - test/lib/time-lord/scale_test.rb
151
+ - test/lib/time-lord/time_test.rb
152
+ - test/lib/time-lord_test.rb
153
+ has_rdoc: