time_math 0.0.1

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: 39225d90e24675a4ff9e489883f110322beb78f9
4
+ data.tar.gz: 9919cc9ccace11a1032fe9645d349e8d1ec3c805
5
+ SHA512:
6
+ metadata.gz: 2aef354f92bedfba4c9787b5ad50ae08d72bdb58dc0507a5e698547b4aae36b8d0f439dacc5310b474c787bd072c70a7df47e493d910a50d69f6c78fd4d3f0a0
7
+ data.tar.gz: 3b403b0ecc504f61f49c83c11e229e3ddd7a7a0c922bf74f072b6cf73a76ffdaa128af7ee714c9e7286f0ad227948e6760fd6f70c7871e9611b3e97720313ca9
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectLevelVcsManager" settingsEditedManually="false">
4
+ <OptionsSetting value="true" id="Add" />
5
+ <OptionsSetting value="true" id="Remove" />
6
+ <OptionsSetting value="true" id="Checkout" />
7
+ <OptionsSetting value="true" id="Update" />
8
+ <OptionsSetting value="true" id="Status" />
9
+ <OptionsSetting value="true" id="Edit" />
10
+ <ConfirmationsSetting value="0" id="Add" />
11
+ <ConfirmationsSetting value="0" id="Remove" />
12
+ </component>
13
+ <component name="ProjectRootManager" version="2" project-jdk-name="RVM: ruby-2.1.5" project-jdk-type="RUBY_SDK" />
14
+ </project>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/time_math.iml" filepath="$PROJECT_DIR$/.idea/time_math.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="FacetManager">
4
+ <facet type="gem" name="Ruby Gem">
5
+ <configuration>
6
+ <option name="GEM_APP_ROOT_PATH" value="$MODULE_DIR$" />
7
+ <option name="GEM_APP_TEST_PATH" value="" />
8
+ <option name="GEM_APP_LIB_PATH" value="$MODULE_DIR$/lib" />
9
+ </configuration>
10
+ </facet>
11
+ </component>
12
+ <component name="NewModuleRootManager">
13
+ <content url="file://$MODULE_DIR$" />
14
+ <orderEntry type="inheritedJdk" />
15
+ <orderEntry type="sourceFolder" forTests="false" />
16
+ </component>
17
+ </module>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,41 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ChangeListManager">
4
+ <option name="TRACKING_ENABLED" value="true" />
5
+ <option name="SHOW_DIALOG" value="false" />
6
+ <option name="HIGHLIGHT_CONFLICTS" value="true" />
7
+ <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
8
+ <option name="LAST_RESOLUTION" value="IGNORE" />
9
+ </component>
10
+ <component name="ChangesViewManager" flattened_view="true" show_ignored="false" />
11
+ <component name="CreatePatchCommitExecutor">
12
+ <option name="PATCH_PATH" value="" />
13
+ </component>
14
+ <component name="NamedScopeManager">
15
+ <order />
16
+ </component>
17
+ <component name="ProjectLevelVcsManager" settingsEditedManually="false">
18
+ <OptionsSetting value="true" id="Add" />
19
+ <OptionsSetting value="true" id="Remove" />
20
+ <OptionsSetting value="true" id="Checkout" />
21
+ <OptionsSetting value="true" id="Update" />
22
+ <OptionsSetting value="true" id="Status" />
23
+ <OptionsSetting value="true" id="Edit" />
24
+ <ConfirmationsSetting value="0" id="Add" />
25
+ <ConfirmationsSetting value="0" id="Remove" />
26
+ </component>
27
+ <component name="ShelveChangesManager" show_recycled="false" />
28
+ <component name="TaskManager">
29
+ <task active="true" id="Default" summary="Default task">
30
+ <option name="number" value="Default" />
31
+ </task>
32
+ <servers />
33
+ </component>
34
+ <component name="VcsContentAnnotationSettings">
35
+ <option name="myLimit" value="2678400000" />
36
+ </component>
37
+ <component name="XDebuggerManager">
38
+ <breakpoint-manager />
39
+ <watches-manager />
40
+ </component>
41
+ </project>
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ 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_math.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Oliver Jesus De Quintos
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.
@@ -0,0 +1,64 @@
1
+ # TimeMath
2
+
3
+ # TimeMath - Computation Helper for Rails Time Formats
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'time_math'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install time_math
18
+
19
+ ## Usage
20
+
21
+ For "strftime" format:
22
+
23
+ SUM:
24
+ TimeMath.strftime(time_a, time_b).sum
25
+
26
+ DIFFERENCE:
27
+ TimeMath.strftime(time_a, time_b).diff
28
+
29
+ For "original" format:
30
+
31
+ DIFFERENCE:
32
+ TimeMath.realtime(time_a, time_b).diff
33
+
34
+ ## Usage in irb
35
+
36
+ require 'time_math'
37
+
38
+ For "strftime" format:
39
+
40
+ SUM:
41
+ TimeMath.strftime(time_a, time_b).sum
42
+
43
+ DIFFERENCE:
44
+ TimeMath.strftime(time_a, time_b).diff
45
+
46
+ For "original" format:
47
+
48
+ DIFFERENCE:
49
+ TimeMath.realtime(time_a, time_b).diff
50
+
51
+
52
+ ## Author
53
+
54
+ By: Oliver Jesus De Quintos
55
+ On: December 2015
56
+
57
+
58
+ ## Contributing
59
+
60
+ 1. Fork it
61
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
62
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
63
+ 4. Push to the branch (`git push origin my-new-feature`)
64
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "time_math"
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
@@ -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,88 @@
1
+ require 'rubygems'
2
+ require "active_support/all"
3
+
4
+ class TimeMath
5
+ private_class_method :new
6
+
7
+ TIME_COMPONENTS = [:add, :diff]
8
+
9
+ def self.strftime(time_a, time_b)
10
+ new(time_a, time_b, "strftime")
11
+ end
12
+
13
+ def self.realtime(time_a, time_b)
14
+ new(time_a, time_b, "realtime")
15
+ end
16
+
17
+ def sum
18
+ case @consumer
19
+ when "strftime"
20
+ strftime_sum
21
+ when "realtime"
22
+ # TODO
23
+ else
24
+ "Nothing here!"
25
+ end
26
+ end
27
+
28
+ def diff
29
+ case @consumer
30
+ when "strftime"
31
+ strftime_diff
32
+ when "realtime"
33
+ realtime_diff(@time_a, @time_b)
34
+ else
35
+ "Nothing here!"
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def initialize(time_a, time_b, consumer)
42
+ @time_a = time_a
43
+ @time_b = time_b
44
+ @consumer = consumer
45
+ end
46
+
47
+ def strftime_sum
48
+ itime_a = convert_strftime(@time_a)
49
+ itime_b = convert_strftime(@time_b)
50
+
51
+ construct_strftime((itime_a + itime_b))
52
+ end
53
+
54
+ def strftime_diff
55
+ itime_a = convert_strftime(@time_a)
56
+ itime_b = convert_strftime(@time_b)
57
+
58
+ time = itime_a - itime_b
59
+ if time < 0
60
+ construct_strftime(time * -1)
61
+ else
62
+ construct_strftime(time)
63
+ end
64
+ end
65
+
66
+ def realtime_diff(time_a, time_b)
67
+ time = (time_a - time_b).to_i.abs
68
+
69
+ hr = time / 3600
70
+ min = (time % 3600) / 60
71
+ sec = (time % 3600) % 60
72
+
73
+ "#{hr.to_s.rjust(2, '0')}:#{min.to_s.rjust(2, '0')}:#{sec.to_s.rjust(2, '0')}"
74
+ end
75
+
76
+ def convert_strftime(strftime)
77
+ time = strftime.split(":")
78
+ (time[0].to_i * 3600) + (time[1].to_i * 60) + (time[2].to_i)
79
+ end
80
+
81
+ def construct_strftime(time)
82
+ hr = time / 3600
83
+ min = (time % 3600) / 60
84
+ sec = (time % 3600) % 60
85
+
86
+ "#{hr.to_s.rjust(2, '0')}:#{min.to_s.rjust(2, '0')}:#{sec.to_s.rjust(2, '0')}"
87
+ end
88
+ end
@@ -0,0 +1,3 @@
1
+ module TimeMath
2
+ VERSION = "0.0.1"
3
+ 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_math/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "time_math"
8
+ spec.version = TimeMath::VERSION
9
+ spec.authors = ["Oliver Jesus De Quintos"]
10
+ spec.email = ["oliverdequintos@yahoo.com"]
11
+
12
+ spec.summary = %q{Time Computation Helper.}
13
+ spec.description = %q{Computes for any time formats in ruby.}
14
+ spec.homepage = "https://github.com/oliverdequintos/time_math"
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 "rspec"
25
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: time_math
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Oliver Jesus De Quintos
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-21 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: rspec
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: Computes for any time formats in ruby.
56
+ email:
57
+ - oliverdequintos@yahoo.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".idea/misc.xml"
64
+ - ".idea/modules.xml"
65
+ - ".idea/time_math.iml"
66
+ - ".idea/vcs.xml"
67
+ - ".idea/workspace.xml"
68
+ - ".rspec"
69
+ - ".travis.yml"
70
+ - CODE_OF_CONDUCT.md
71
+ - Gemfile
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - bin/console
76
+ - bin/setup
77
+ - lib/time_math.rb
78
+ - lib/time_math/version.rb
79
+ - time_math.gemspec
80
+ homepage: https://github.com/oliverdequintos/time_math
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.4.6
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Time Computation Helper.
104
+ test_files: []