time_spent 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: 5c15ccb7a0860ba03f0656b1d6635ac6d650724c
4
+ data.tar.gz: 5237a18d19f45c248d0ad10c24e9ade5a4738576
5
+ SHA512:
6
+ metadata.gz: 10981ba5003e5a055b1ada44184faf6233a1843c375b223d3c31d6d68d8c883a10d63d09af16ebabccc82a0b220cd8b1c093d6a57697abb09e0058c83287bf05
7
+ data.tar.gz: e22b3b22834808a88d55de5732ed46091fbcd6eed2db35b0667fd545ead2b4e585411e582bab2ba99ea7d18f6dceeb5d2be6110ec0652e1a0c47ca2e9c065b9d
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
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in time_spent.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # TimeSpent
2
+
3
+ Calculate the time spent between several markings
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'time_spent'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install time_spent
21
+
22
+ ## Usage
23
+
24
+
25
+ Ex.: `['8:00', '9:00', '13:30', '15:45']`
26
+
27
+ Format suported : `H:M`
28
+
29
+ ```irb
30
+ require 'time_spent'
31
+ => true
32
+ TimeSpent::Markings.new.calculate(Time.now, ['8:00','9:00'])
33
+ => "01:00"
34
+ duration = TimeSpent::Markings.new.calculate(Time.now, ['8:00','9:00'])
35
+ => "01:00"
36
+ TimeSpent::Markings.new.to_sec duration
37
+ => 3600
38
+
39
+
40
+ ```
41
+
42
+ ## Development
43
+
44
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
45
+
46
+ 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).
47
+
48
+ ## Contributing
49
+
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/andrelugomes/time_spent.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "time_spent"
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,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,9 @@
1
+ module TimeSpent
2
+ module Exceptions
3
+ class MarkingsNotEven < StandardError
4
+ def initialize(msg="My default message")
5
+ super msg
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module TimeSpent
2
+ VERSION = "0.1.0"
3
+ end
data/lib/time_spent.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'time_spent/version'
2
+ require 'time_spent/exceptions/markings_not_even'
3
+ require 'time_difference'
4
+ require 'ruby-duration'
5
+
6
+ module TimeSpent
7
+ class Markings
8
+ def calculate(day, markings)
9
+ total = 0
10
+ if markings.size.even?
11
+ validate_format markings
12
+ markings.each_slice(2) do |start_time,end_time|
13
+ start_datetime = Time.new(day.year, day.month, day.day, start_time.split(':').first, start_time.split(':').last)
14
+ end_datetime = Time.new(day.year, day.month, day.day, end_time.split(':').first, end_time.split(':').last)
15
+ total += TimeDifference.between(start_datetime, end_datetime).in_seconds
16
+ end
17
+ Duration.new(total).format('%H:%M')
18
+ else
19
+ raise Exceptions::MarkingsNotEven , 'Markings needs to be even for calculation.'
20
+ end
21
+ end
22
+
23
+ def to_sec(duration)
24
+ a = duration.split(':')
25
+ Duration.new(hours: a.first, minutes: a.last).total
26
+ end
27
+
28
+ private
29
+
30
+ def validate_format(markings)
31
+ #raise InvalidFormat unless...
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'time_spent/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "time_spent"
8
+ spec.version = TimeSpent::VERSION
9
+ spec.authors = ["André Luis"]
10
+ spec.email = ["andrelugomes@gmail.com"]
11
+
12
+ spec.summary = %q{Calculate time spent}
13
+ spec.description = %q{Given a array of markings like '['8:00', '9:00']'}
14
+ spec.homepage = "https://github.com/andrelugomes"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.13"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "ruby-duration", "3.2.3"
35
+ spec.add_development_dependency "time_difference", "0.5.0"
36
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: time_spent
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - André Luis
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-23 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.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
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: ruby-duration
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 3.2.3
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 3.2.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: time_difference
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.5.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.5.0
69
+ description: Given a array of markings like '['8:00', '9:00']'
70
+ email:
71
+ - andrelugomes@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - README.md
79
+ - Rakefile
80
+ - bin/console
81
+ - bin/setup
82
+ - lib/time_spent.rb
83
+ - lib/time_spent/exceptions/markings_not_even.rb
84
+ - lib/time_spent/version.rb
85
+ - time_spent.gemspec
86
+ homepage: https://github.com/andrelugomes
87
+ licenses: []
88
+ metadata:
89
+ allowed_push_host: https://rubygems.org
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.5.1
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Calculate time spent
110
+ test_files: []