time_tally 0.0.1

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
+ SHA256:
3
+ metadata.gz: 3d559033e2084b070f736ad6d56060c1fb240b47d93de9a9d91bd0e323cf0fc0
4
+ data.tar.gz: 8c4ddee62e46958f4b95143bbec2188fbea6d97673d47aa1477ae9e36acde03f
5
+ SHA512:
6
+ metadata.gz: 4074168a943c5b0c2d8fee58a653cd3011b9012bd795d3baad0d9b6cbe85df247052fe8e2228fa63c80efa8111f6c56a9becc7abffe20544310f60479efcba69
7
+ data.tar.gz: 10cbf9d3ebefce525bf521ae65250740ff8471f15c87b58813cfafdb4a7bce3e3d23cf7094e95efc69c519a95f2ac6fc643c82f138860a8a9dce7e0176ab480e
@@ -0,0 +1,3 @@
1
+ # These are supported funding model platforms
2
+
3
+ patreon: tomtt
@@ -0,0 +1,33 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ main ]
13
+ pull_request:
14
+ branches: [ main ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+
21
+ steps:
22
+ - uses: actions/checkout@v2
23
+ - name: Set up Ruby
24
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
25
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
26
+ # uses: ruby/setup-ruby@v1
27
+ uses: ruby/setup-ruby@21351ecc0a7c196081abca5dc55b08f085efe09a
28
+ with:
29
+ ruby-version: 2.6
30
+ - name: Install dependencies
31
+ run: bundle install
32
+ - name: Run tests
33
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ Gemfile.lock
13
+ dummy
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format progress
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,18 @@
1
+ Layout/LineLength:
2
+ Max: 120
3
+ Style/Documentation:
4
+ Enabled: false
5
+ Style/FrozenStringLiteralComment:
6
+ Enabled: false
7
+ Style/StringLiterals:
8
+ Enabled: false
9
+ Style/BlockDelimiters:
10
+ EnforcedStyle: semantic
11
+ Layout/SpaceInsideHashLiteralBraces:
12
+ EnforcedStyle: no_space
13
+ AllCops:
14
+ TargetRubyVersion: 2.4.0
15
+ NewCops: enable
16
+ Metrics/BlockLength:
17
+ Exclude:
18
+ - 'spec/**/*_spec.rb'
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.2
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders 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, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at tom.tenthij@fuga.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in time_tally.gemspec
4
+ gemspec
5
+
6
+ gem "guard-rspec"
7
+ gem "pry-byebug"
8
+ gem "rake", "~> 12.0"
9
+ gem "rspec", "~> 3.10.0"
10
+ gem "simplecov"
11
+ gem "solargraph"
12
+ gem "standard"
data/Guardfile ADDED
@@ -0,0 +1,6 @@
1
+ guard :rspec, cmd: "rspec", failed_mode: :keep do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^spec/support/(.+)\.rb$})
4
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
5
+ watch("spec/spec_helper.rb") { "spec" }
6
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Tom ten Thij
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
+ # TimeTally
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/time_tally`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'time_tally'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install time_tally
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tomtt/time_tally. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/tomtt/time_tally/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the TimeTally project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/tomtt/time_tally/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "time_tally"
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(__FILE__)
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
data/exe/time_tally ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bundle exec ruby
2
+ # This script can only be run from elsewhere if BUNDLE_GEMFILE of this project
3
+ # has been set.
4
+
5
+ require "time_tally"
6
+ TimeTally::Shell.run(ARGV, out: $stdout, err: $stderr) do |options|
7
+ TimeTally::DoSomething.new(options, out: $stdout, err: $stderr).show
8
+ end
@@ -0,0 +1,34 @@
1
+ Encoding.default_external = "UTF-8"
2
+
3
+ module TimeTally
4
+ class DoSomething
5
+ def initialize(options, out: stdout, err: stderr)
6
+ @options = options
7
+ @out = out
8
+ @err = err
9
+ end
10
+
11
+ def show
12
+ lines = ARGF.read.split("\n")
13
+
14
+ time_indices = lines.each_with_index.to_a.select { |s| s[0] =~ /^\d+:\d{2}:\d{2}$/ }
15
+ lines_per_entry = time_indices[1][1] - time_indices[0][1]
16
+
17
+ entries = []
18
+ line_type_counter = 0
19
+ lines.each do |line|
20
+ next if line_type_counter == 0 && line == "\t"
21
+ if line_type_counter == 0
22
+ entries << []
23
+ end
24
+
25
+ entries.last << line
26
+ line_type_counter = (line_type_counter + 1) % lines_per_entry
27
+ end
28
+
29
+ tallier = TimeTallier.new
30
+ entries.each { |e| tallier.add_entry(TimeEntry.from_lines(e)) }
31
+ tallier.print_report
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,39 @@
1
+ module TimeTally
2
+ class Duration
3
+ attr_accessor :h, :m, :s
4
+
5
+ def initialize(str = nil)
6
+ if str
7
+ @h, @m, @s = str.split(":").map(&:to_i)
8
+ normalize
9
+ else
10
+ @h = @m = @s = 0
11
+ end
12
+ end
13
+
14
+ def normalize
15
+ if @s > 59
16
+ @m += @s / 60
17
+ @s %= 60
18
+ end
19
+
20
+ if @m > 59
21
+ @h += @m / 60
22
+ @m %= 60
23
+ end
24
+ end
25
+
26
+ def +(other)
27
+ result = Duration.new
28
+ result.s = s + other.s
29
+ result.m = m + other.m
30
+ result.h = h + other.h
31
+ result.normalize
32
+ result
33
+ end
34
+
35
+ def to_s
36
+ "%d:%02d:%02d" % [h, m, s]
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,47 @@
1
+ require "optparse"
2
+
3
+ module TimeTally
4
+ class Shell
5
+ BANNER = <<~"MSG".freeze
6
+ usage: #{$PROGRAM_NAME}
7
+
8
+ Takes copied data from the report screen of toggle and formats a total amount of time per task
9
+ MSG
10
+
11
+ def self.usage(err: $stderr)
12
+ err.puts BANNER
13
+ exit 1
14
+ end
15
+
16
+ def self.run(argv, out: $stdout, err: $stderr)
17
+ options = gather_options(argv)
18
+
19
+ out.puts "version: #{TimeTally::VERSION}" if options.delete(:show_version)
20
+
21
+ usage(err: err) unless argv.size == 0
22
+
23
+ yield(options)
24
+ end
25
+
26
+ def self.gather_options(argv) # rubocop:disable Metrics/MethodLength
27
+ options = {
28
+ show_version: false
29
+ }
30
+
31
+ OptionParser.new { |parser|
32
+ parser.banner = BANNER
33
+
34
+ parser.on("-v", "--version", "Show version") do |version|
35
+ options[:show_version] = version
36
+ end
37
+
38
+ parser.on("-h", "--help", "Prints this help") do
39
+ puts parser
40
+ exit
41
+ end
42
+ }.parse! argv
43
+
44
+ options
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,20 @@
1
+ module TimeTally
2
+ class TimeEntry
3
+ attr_reader :task, :duration
4
+
5
+ def initialize(task:, duration:)
6
+ @task = task
7
+ @duration = duration
8
+ end
9
+
10
+ def self.from_lines(lines)
11
+ task = lines[0]
12
+ duration = lines[1..-1].select { |s| s =~ /^\d+:\d{2}:\d{2}$/ }.first
13
+ TimeEntry.new(task: task, duration: Duration.new(duration))
14
+ end
15
+
16
+ def to_s
17
+ "%-40s %s" % [task, duration]
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,27 @@
1
+ module TimeTally
2
+ class TimeTallier
3
+ def initialize
4
+ @tasks = {}
5
+ end
6
+
7
+ def add_entry(time_entry)
8
+ @tasks[time_entry.task] ||= []
9
+ @tasks[time_entry.task] << time_entry.duration
10
+ end
11
+
12
+ def total_time_for_task(task)
13
+ @tasks[task].inject(Duration.new) { |a,b| a + b }
14
+ end
15
+
16
+ def print_report
17
+ total_time = Duration.new
18
+ puts "-" * 68
19
+ @tasks.keys.each do |k|
20
+ puts "%-60s %s" % [k, total_time_for_task(k)]
21
+ total_time += total_time_for_task(k)
22
+ end
23
+ puts "-" * 68
24
+ puts "%-60s %s" % ["", total_time]
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module TimeTally
2
+ VERSION = "0.0.1".freeze
3
+ end
data/lib/time_tally.rb ADDED
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ Encoding.default_external = "UTF-8"
4
+
5
+ require "time_tally/version"
6
+ require "zeitwerk"
7
+
8
+ module TimeTally
9
+ class << self
10
+ attr_reader :loader
11
+
12
+ def root
13
+ Pathname.new(File.absolute_path(File.join(File.dirname(__FILE__), "..")))
14
+ end
15
+
16
+ def setup_loader
17
+ @loader = Zeitwerk::Loader.for_gem
18
+ @loader.enable_reloading
19
+ # @loader.push_dir(ActiveCore.root.join("non-lib/code_dir"))
20
+ @loader.setup
21
+ @loader.eager_load
22
+ end
23
+ end
24
+ end
25
+
26
+ TimeTally.setup_loader
@@ -0,0 +1,22 @@
1
+ require_relative "lib/time_tally/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "time_tally"
5
+ spec.version = TimeTally::VERSION
6
+ spec.authors = ["Tom ten Thij"]
7
+ spec.email = ["code@tomtenthij.nl"]
8
+
9
+ spec.summary = "A skeleton to start a gem from"
10
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
11
+
12
+ # Specify which files should be added to the gem when it is released.
13
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
14
+ spec.files = Dir.chdir(File.expand_path(__dir__)) {
15
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency("zeitwerk")
22
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: time_tally
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tom ten Thij
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-09-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: zeitwerk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email:
29
+ - code@tomtenthij.nl
30
+ executables:
31
+ - time_tally
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".github/FUNDING.yml"
36
+ - ".github/workflows/ruby.yml"
37
+ - ".gitignore"
38
+ - ".rspec"
39
+ - ".rubocop.yml"
40
+ - ".travis.yml"
41
+ - CODE_OF_CONDUCT.md
42
+ - Gemfile
43
+ - Guardfile
44
+ - LICENSE.txt
45
+ - README.md
46
+ - Rakefile
47
+ - bin/console
48
+ - bin/setup
49
+ - exe/time_tally
50
+ - lib/time_tally.rb
51
+ - lib/time_tally/do_something.rb
52
+ - lib/time_tally/duration.rb
53
+ - lib/time_tally/shell.rb
54
+ - lib/time_tally/time_entry.rb
55
+ - lib/time_tally/time_tallier.rb
56
+ - lib/time_tally/version.rb
57
+ - time_tally.gemspec
58
+ homepage:
59
+ licenses: []
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 2.4.0
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubygems_version: 3.0.3
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: A skeleton to start a gem from
80
+ test_files: []