length_of_time 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 640a3a16b1263c9738dc9cf47244fbd52f642307
4
+ data.tar.gz: 50919f80f14145d5b6ac879c4ea0852dbd307455
5
+ SHA512:
6
+ metadata.gz: 22c9f6e40778954682103e186914af4d932a976a25cad56bdf658b41a656b89ca37f4a2736e220c29277ae2073cf72dcf1bf246a64bb52c1c6d33a3d6c6e9d8d
7
+ data.tar.gz: 3ded3a2fb3024b9c79e74e415f9a623c6a5f09dcaa257d306dc4a44690f76c9e20d5b14dd60806317122719e2790806ba1ee81c07b1ac51aae531c34dd7d49af
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Charles Ray Shisler III
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # Length Of Time
2
+
3
+ A miniature DSL for describing lengths of time.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'length_of_time'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install length_of_time
20
+
21
+ ## Usage
22
+
23
+ Require the gem:
24
+
25
+ ```ruby
26
+ require 'length_of_time'
27
+ ```
28
+
29
+ Use the various methods that we monkey-patch onto Numeric:
30
+
31
+ ```ruby
32
+ # Default unit to return is :seconds
33
+ puts 10.minutes # => 600.0
34
+
35
+ # Can also convert into other units of time
36
+ puts 7.days in: :weeks # => 1.0
37
+
38
+ # Return Floats so that unit conversion does not suffer from Integer division
39
+ puts 10.days in: :weeks # => 1.4285714285714286
40
+
41
+ # Method calls on Numeric literals can be either singular or plural
42
+ puts 1.hour # => 3600.0
43
+ puts 2.hours # => 7200.0
44
+
45
+ # When converting into another unit of time, unit must be plural
46
+ puts 500.milliseconds in: :minutes # Correct
47
+ puts 750.milliseconds in: :minute # Incorrect - will give an error
48
+
49
+ # Full list of units supported:
50
+ # Singular [:millisecond, :second, :minute, :hour, :day, :week, :fortnight]
51
+ # Plural [:milliseconds, :seconds, :minutes, :hours, :days, :weeks, :fortnights]
52
+ ```
53
+
54
+ ## Development
55
+
56
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
57
+
58
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
59
+
60
+ ## Contributing
61
+
62
+ Bug reports and pull requests are welcome on GitHub at https://github.com/craysiii/length_of_time.
63
+
64
+ ## License
65
+
66
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'rspec'
5
+ require 'length_of_time'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ require 'pry'
12
+ Pry.start
13
+
14
+
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ class Numeric
2
+ SECONDS_PER_MILLISECOND = 1.0 / 1000
3
+ SECONDS_PER_SECOND = 1.0
4
+ SECONDS_PER_MINUTE = 60.0
5
+ SECONDS_PER_HOUR = 3_600.0
6
+ SECONDS_PER_DAY = 86_400.0
7
+ SECONDS_PER_WEEK = 604_800.0
8
+ SECONDS_PER_FORTNIGHT = 1_209_600.0
9
+
10
+ TIME = {
11
+ milliseconds: SECONDS_PER_MILLISECOND,
12
+ seconds: SECONDS_PER_SECOND,
13
+ minutes: SECONDS_PER_MINUTE,
14
+ hours: SECONDS_PER_HOUR,
15
+ days: SECONDS_PER_DAY,
16
+ weeks: SECONDS_PER_WEEK,
17
+ fortnights: SECONDS_PER_FORTNIGHT
18
+ }.freeze
19
+
20
+ TIME.each_key do |method|
21
+ define_method(method) do |opt = { in: :seconds }|
22
+ self * TIME[method] / TIME[opt[:in]]
23
+ end
24
+ alias_method method.to_s.chop, method
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module LengthOfTime
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,2 @@
1
+ require 'length_of_time/version'
2
+ require 'length_of_time/numeric'
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: length_of_time
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Charles Ray Shisler III
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-13 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.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
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'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - charles@cray.io
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - LICENSE.txt
77
+ - README.md
78
+ - bin/console
79
+ - bin/setup
80
+ - lib/length_of_time.rb
81
+ - lib/length_of_time/numeric.rb
82
+ - lib/length_of_time/version.rb
83
+ homepage: https://github.com/craysiii/length_of_time
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.6.11
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: DSL for lengths of time, similar to ActiveSupport::Numeric#seconds.
107
+ test_files: []