time_rounder 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 83c7f67939513ab89221fcac1302d455f344d3b6
4
+ data.tar.gz: 8747c4b4290d33daa70777fb9f1e1328e76275f1
5
+ SHA512:
6
+ metadata.gz: 676e82cb4529466f8b0e4ace3d9abb9a908bccf936a6fce9be8618096e70522b68aa20728dbe6532d3c82f3066ae0882b0f16df2dd7be7f1c0f8657f0a5571cb
7
+ data.tar.gz: cc3d8f53304905fe27564f9adadd5061f978367343399dd8dfe512c8509270373c03a3bd34a5c13d8b99611bbeb916a5ed676efbbbe683c3e295e33c09590420
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /doc/
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ - 2.1.7
5
+ - 2.0.0
6
+ - 1.9.3
7
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in time_rounder.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Ryan
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,43 @@
1
+ # TimeRounder
2
+
3
+ TimeRounder is a gem born to solve a problem, which is to round time, without all the complex math. TimeRounder defeats all the complex math used to round time, by using logic.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'time_rounder'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install time_rounder
20
+
21
+ ## Usage
22
+
23
+ TimeRounder has simple methods to access internal classes that calculate the rounded time.
24
+
25
+ ```ruby
26
+ TimeRounder.seconds_to_hours(seconds)
27
+ ```
28
+
29
+ ## Development
30
+
31
+ TimeRounder will continue to be developed adding features and functionality. Some of those features currently planned are:
32
+
33
+ - Adding 5, 10, 20 minute rounding schedules.
34
+ - Adding rounding of a date/time object.
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rebelweb/time_rounder. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
39
+
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "time_rounder"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,65 @@
1
+ ##
2
+ # Takes seconds and returns a decimal of hours and partial hours.
3
+
4
+ module TimeRounder
5
+ class RoundedTimeFromSeconds
6
+
7
+ ##
8
+ # Returns the total rounded hours in the number of seconds
9
+ def rounded_time
10
+ time = hours + quarter_hours
11
+ time += 1 if add_hour?
12
+ time
13
+ end
14
+
15
+ private
16
+
17
+ def initialize(seconds)
18
+ @@seconds = seconds
19
+ end
20
+
21
+ ##
22
+ # Determines if an hour needs to be added to total if the partial is rounding up at the end of an hour
23
+
24
+ def add_hour?
25
+ add_hour_array.include?(minutes)
26
+ end
27
+
28
+ ##
29
+ # Takes the number of seconds and returns the number of hours as an integer.
30
+
31
+ def hours
32
+ @@seconds / 3600
33
+ end
34
+
35
+ ##
36
+ # Takes the remainder of seconds after the hours removed and retrieve the left over minutes.
37
+
38
+ def minutes
39
+ (@@seconds % 3600) / 60
40
+ end
41
+
42
+ ##
43
+ # Takes the number of minutes in the total of seconds after hours are removed, to retrieve the decimal portion of the total.
44
+
45
+ def quarter_hours
46
+ minutes_hash[minutes]
47
+ end
48
+
49
+ ##
50
+ # This is where the magic happens. This hash contains every minute of an hour and what decimal partial hours it rounds to.
51
+ # This partial is added to the total.
52
+
53
+ def minutes_hash
54
+ {0 => 0.0, 1 => 0.0, 2 => 0.0, 3 => 0.0, 4 => 0.0, 5 => 0.0, 6 => 0.0, 7 => 0.0, 8 => 0.25, 9 => 0.25, 10 => 0.25, 11 => 0.25, 12 => 0.25, 13 => 0.25, 14 => 0.25, 15 => 0.25, 16 => 0.25, 17 => 0.25, 18 => 0.25, 19 => 0.25, 20 => 0.25, 21 => 0.25, 22 => 0.25, 23 => 0.50, 24 => 0.50, 25 => 0.50, 26 => 0.50, 27 => 0.50, 28 => 0.50, 29 => 0.50, 30 => 0.50, 31 => 0.50, 32 => 0.50, 33 => 0.50, 34 => 0.50, 35 => 0.50, 36 => 0.50, 37 => 0.50, 38 => 0.75, 39 => 0.75, 40 => 0.75, 41 => 0.75, 42 => 0.75, 43 => 0.75, 44 => 0.75, 45 => 0.75, 46 => 0.75, 47 => 0.75, 48 => 0.75, 49 => 0.75, 50 => 0.75, 51 => 0.75, 52 => 0.75, 53 => 0.0, 54 => 0.0, 55 => 0.0, 56 => 0.0, 57 => 0.0, 58 => 0.0, 59 => 0.0}
55
+ end
56
+
57
+ ##
58
+ # This array is used to determine if it close to the next hour and an hour needs added to the total.
59
+ # The partial hours will show as zero, and hours is added to correct the total.
60
+
61
+ def add_hour_array
62
+ [53, 54, 55, 56, 57, 58, 59]
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,3 @@
1
+ module TimeRounder
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,16 @@
1
+ require "time_rounder/version"
2
+ require "time_rounder/rounded_time_from_seconds"
3
+
4
+ ##
5
+ # TimeRounder is a library to round time.
6
+
7
+ module TimeRounder
8
+
9
+ ##
10
+ # Takes number of seconds and returns hours and partial hours in decimal form.
11
+
12
+ def self.seconds_to_hours(seconds)
13
+ TimeRounder::RoundedTimeFromSeconds.new(seconds).rounded_time
14
+ end
15
+
16
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'time_rounder/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "time_rounder"
8
+ spec.version = TimeRounder::VERSION
9
+ spec.authors = ["Ryan"]
10
+ spec.email = ["rebelwebdevelopment@gmail.com"]
11
+
12
+ spec.summary = %q{ Round time with ease }
13
+ spec.description = %q{ Round time using logic and not complex math.}
14
+ spec.homepage = "https://github.com/rebelweb/time_rounder"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "minitest"
25
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: time_rounder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-01 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: " Round time using logic and not complex math."
56
+ email:
57
+ - rebelwebdevelopment@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - CODE_OF_CONDUCT.md
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/time_rounder.rb
72
+ - lib/time_rounder/rounded_time_from_seconds.rb
73
+ - lib/time_rounder/version.rb
74
+ - time_rounder.gemspec
75
+ homepage: https://github.com/rebelweb/time_rounder
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.4.8
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Round time with ease
99
+ test_files: []