From 1be2836358db269031191d13e43ecb5ab865e786 Mon Sep 17 00:00:00 2001 From: Danilo Jeremias da Silva Date: Sat, 30 Sep 2023 23:55:44 -0300 Subject: [PATCH 1/2] Update gems dependencies --- .coveralls.yml | 1 - .github/workflows/{ci.yml => main.yml} | 9 +- .hound.yml | 3 - .rubocop.yml | 25 +++-- CODE_OF_CONDUCT.md | 104 +++++++++++---------- Gemfile | 15 ++- Gemfile.lock | 95 ++++++++++++------- LICENSE.txt | 2 +- README.md | 54 ++--------- Rakefile | 10 +- bin/console | 10 +- lib/tempus.rb | 28 +++--- lib/tempus/parser.rb | 4 +- lib/tempus/version.rb | 2 +- spec/spec_helper.rb | 11 +-- spec/tempus/tempus_helper_spec.rb | 26 +++--- spec/tempus_spec.rb | 124 ++++++++++++------------- tempus.gemspec | 48 +++++----- 18 files changed, 294 insertions(+), 277 deletions(-) delete mode 100644 .coveralls.yml rename .github/workflows/{ci.yml => main.yml} (74%) delete mode 100644 .hound.yml diff --git a/.coveralls.yml b/.coveralls.yml deleted file mode 100644 index 749a842..0000000 --- a/.coveralls.yml +++ /dev/null @@ -1 +0,0 @@ -repo_token: ELpdfYjCf7cMiE663I70rR0V4mcZwmeia diff --git a/.github/workflows/ci.yml b/.github/workflows/main.yml similarity index 74% rename from .github/workflows/ci.yml rename to .github/workflows/main.yml index c1420f7..337b761 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/main.yml @@ -10,15 +10,16 @@ on: jobs: build: runs-on: ubuntu-latest - + name: Ruby ${{ matrix.ruby }} strategy: matrix: ruby: - - 2.7.4 - - 3.0.2 + - '2.7.4' + - '3.0.2' + - '3.2.2' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: diff --git a/.hound.yml b/.hound.yml deleted file mode 100644 index 05a83cf..0000000 --- a/.hound.yml +++ /dev/null @@ -1,3 +0,0 @@ -rubocop: - config_file: .rubocop.yml - version: 0.80.0 diff --git a/.rubocop.yml b/.rubocop.yml index 2a853cc..cae6512 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,17 +1,24 @@ +require: + - rubocop-rake + - rubocop-rspec + - rubocop-performance AllCops: NewCops: enable + TargetRubyVersion: 2.7 -Metrics/BlockLength: - Exclude: - - 'tempus.gemspec' - - 'spec/**/*.rb' +Style/StringLiterals: + Enabled: true + EnforcedStyle: double_quotes + +Style/StringLiteralsInInterpolation: + Enabled: true + EnforcedStyle: double_quotes Layout/LineLength: - Exclude: - - 'tempus.gemspec' + Max: 120 -Style/RedundantRegexpEscape: +RSpec/MultipleExpectations: Enabled: false -Gemspec/RequireMFA: - Enabled: false \ No newline at end of file +RSpec/ExampleLength: + Max: 25 \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 7fd1970..82874ea 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -2,73 +2,83 @@ ## Our Pledge -In the interest of fostering an open and welcoming environment, we as -contributors and maintainers pledge to making participation in our project and -our community a harassment-free experience for everyone, regardless of age, body -size, disability, ethnicity, gender identity and expression, level of experience, -nationality, personal appearance, race, religion, or sexual identity and -orientation. +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. + +We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. ## Our Standards -Examples of behavior that contributes to creating a positive environment -include: +Examples of behavior that contributes to a positive environment for our community include: -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall community -Examples of unacceptable behavior by participants include: +Examples of unacceptable behavior include: -* The use of sexualized language or imagery and unwelcome sexual attention or -advances -* Trolling, insulting/derogatory comments, and personal or political attacks +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks * Public or private harassment -* Publishing others' private information, such as a physical or electronic - address, without explicit permission +* Publishing others' private information, such as a physical or email + address, without their explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting -## Our Responsibilities +## Enforcement Responsibilities -Project maintainers are responsible for clarifying the standards of acceptable -behavior and are expected to take appropriate and fair corrective action in -response to any instances of unacceptable behavior. +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. -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, or to ban temporarily or -permanently any contributor for other behaviors that they deem inappropriate, -threatening, offensive, or harmful. +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. ## Scope -This Code of Conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. Examples of -representing a project or community include using an official project e-mail -address, posting via an official social media account, or acting as an appointed -representative at an online or offline event. Representation of a project may be -further defined and clarified by project maintainers. +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. ## Enforcement -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team at daniloj.dasilva@gmail.com. All -complaints will be reviewed and investigated and will result in a response that -is deemed necessary and appropriate to the circumstances. The project team is -obligated to maintain confidentiality with regard to the reporter of an incident. -Further details of specific enforcement policies may be posted separately. +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at daniloj.dasilva@gmail.com. All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. + +**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. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of actions. -Project maintainers who do not follow or enforce the Code of Conduct in good -faith may face temporary or permanent repercussions as determined by other -members of the project's leadership. +**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. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. + +**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. + +### 4. Permanent Ban + +**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. + +**Consequence**: A permanent ban from any sort of public interaction within the community. ## Attribution -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, -available at [https://contributor-covenant.org/version/1/4][version] +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, +available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org -[homepage]: https://contributor-covenant.org -[version]: https://contributor-covenant.org/version/1/4/ +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. diff --git a/Gemfile b/Gemfile index 1b2c9a9..fd1dcb0 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,17 @@ # frozen_string_literal: true -source 'https://rubygems.org' - -git_source(:github) { |repo_name| "https://github.com/#{repo_name}" } +source "https://rubygems.org" # Specify your gem's dependencies in tempus.gemspec gemspec + +gem "rake", "~> 13.0" + +group :test do + gem "rspec", "~> 3.0" + gem "rubocop", "~> 1.21" + gem "rubocop-performance", require: false + gem "rubocop-rake", require: false + gem "rubocop-rspec", require: false + gem "simplecov", require: false +end diff --git a/Gemfile.lock b/Gemfile.lock index d0345d9..5bbf5a3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,68 +1,97 @@ PATH remote: . specs: - tempus (1.0.3) + tempus (1.1.0) activesupport (> 5) GEM remote: https://rubygems.org/ specs: - activesupport (7.0.4) + activesupport (7.0.6) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) - concurrent-ruby (1.1.10) - coveralls (0.8.23) - json (>= 1.8, < 3) - simplecov (~> 0.16.1) - term-ansicolor (~> 1.3) - thor (>= 0.19.4, < 2.0) - tins (~> 1.6) + ast (2.4.2) + concurrent-ruby (1.2.2) diff-lcs (1.5.0) docile (1.4.0) - i18n (1.12.0) + i18n (1.14.1) concurrent-ruby (~> 1.0) - json (2.6.2) - minitest (5.16.3) + json (2.6.3) + language_server-protocol (3.17.0.3) + minitest (5.19.0) + parallel (1.23.0) + parser (3.2.2.3) + ast (~> 2.4.1) + racc + racc (1.7.1) + rainbow (3.1.1) rake (13.0.6) + regexp_parser (2.8.1) + rexml (3.2.5) rspec (3.12.0) rspec-core (~> 3.12.0) rspec-expectations (~> 3.12.0) rspec-mocks (~> 3.12.0) - rspec-core (3.12.0) + rspec-core (3.12.2) rspec-support (~> 3.12.0) - rspec-expectations (3.12.0) + rspec-expectations (3.12.3) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) - rspec-mocks (3.12.0) + rspec-mocks (3.12.6) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) - rspec-support (3.12.0) - simplecov (0.16.1) + rspec-support (3.12.1) + rubocop (1.54.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.2.2.3) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.28.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.29.0) + parser (>= 3.2.1.0) + rubocop-capybara (2.18.0) + rubocop (~> 1.41) + rubocop-factory_bot (2.23.1) + rubocop (~> 1.33) + rubocop-performance (1.18.0) + rubocop (>= 1.7.0, < 2.0) + rubocop-ast (>= 0.4.0) + rubocop-rake (0.6.0) + rubocop (~> 1.0) + rubocop-rspec (2.23.0) + rubocop (~> 1.33) + rubocop-capybara (~> 2.17) + rubocop-factory_bot (~> 2.22) + ruby-progressbar (1.13.0) + simplecov (0.22.0) docile (~> 1.1) - json (>= 1.8, < 3) - simplecov-html (~> 0.10.0) - simplecov-html (0.10.2) - sync (0.5.0) - term-ansicolor (1.7.1) - tins (~> 1.0) - thor (1.2.1) - tins (1.31.1) - sync - tzinfo (2.0.5) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.12.3) + simplecov_json_formatter (0.1.4) + tzinfo (2.0.6) concurrent-ruby (~> 1.0) + unicode-display_width (2.4.2) PLATFORMS - ruby + x86_64-linux DEPENDENCIES - bundler (~> 2.1) - coveralls (~> 0.8) rake (~> 13.0) - rspec (~> 3.9) - simplecov (~> 0.9) + rspec (~> 3.0) + rubocop (~> 1.21) + rubocop-performance + rubocop-rake + rubocop-rspec + simplecov tempus! BUNDLED WITH - 2.2.22 + 2.4.15 diff --git a/LICENSE.txt b/LICENSE.txt index 9146d53..36df9ed 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2019 Danilo Jeremias da Silva +Copyright (c) 2023 Danilo Jeremias da Silva Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 67a0dc1..95b7560 100644 --- a/README.md +++ b/README.md @@ -1,69 +1,35 @@ # Tempus - - Gem Version - +TODO: Delete this and the text below, and describe your gem -Gem to efficiently manipulate the time, adding, subtracting and converting hours. +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/tempus`. To experiment with that code, run `bin/console` for an interactive prompt. ## Installation -Add this line to your application's Gemfile: +TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org. -```ruby -gem 'tempus' -``` +Install the gem and add to the application's Gemfile by executing: -And then execute: + $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG - $ bundle install +If bundler is not being used to manage dependencies, install the gem by executing: -Or install it yourself as: - - $ gem install tempus + $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG ## Usage - With this gem you can manage durations of time. - -### Initialize with duration -```ruby - hours = Tempus.new(30.hours + 5.minutes + 3.seconds) - => - hours.value_in_minutes - => 1805.05 - hours.to_s("%H hours and %M minutes") - => "30 hours and 05 minutes" -``` -### Convert from other types -```ruby - hours = "35:05:01".to_tempus - => - hours + 6.hours - => -``` -```ruby - Tempus.new(Time.now) - => -``` - -### Sum durations - -```ruby - "1:00:00".to_tempus + "2:00" - => -``` + +TODO: Write usage instructions here ## Development 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. -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). +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). ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/dannnylo/tempus. 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/dannnylo/tempus/blob/master/CODE_OF_CONDUCT.md). - ## License The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). diff --git a/Rakefile b/Rakefile index 82bb534..cca7175 100644 --- a/Rakefile +++ b/Rakefile @@ -1,8 +1,12 @@ # frozen_string_literal: true -require 'bundler/gem_tasks' -require 'rspec/core/rake_task' +require "bundler/gem_tasks" +require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) -task default: :spec +require "rubocop/rake_task" + +RuboCop::RakeTask.new + +task default: %i[spec rubocop] diff --git a/bin/console b/bin/console index 4195b78..91ecec2 100755 --- a/bin/console +++ b/bin/console @@ -1,15 +1,11 @@ #!/usr/bin/env ruby # frozen_string_literal: true -require 'bundler/setup' -require 'tempus' +require "bundler/setup" +require "tempus" # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. -# (If you use this, don't forget to add pry to your Gemfile!) -# require "pry" -# Pry.start - -require 'irb' +require "irb" IRB.start(__FILE__) diff --git a/lib/tempus.rb b/lib/tempus.rb index 9762e32..01b5bbe 100644 --- a/lib/tempus.rb +++ b/lib/tempus.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -require 'active_support' -require 'active_support/core_ext' +require "active_support" +require "active_support/core_ext" -require 'tempus/version' -require 'tempus/parser' -require 'tempus/tempus_helper' +require_relative "tempus/version" +require_relative "tempus/parser" +require_relative "tempus/tempus_helper" # Class to manipulate efficiently time #=== Example: @@ -14,9 +14,9 @@ class Tempus class Error < StandardError; end - HOURS_REGEX = /(\%h|\%hh|\%H|\%HH)/.freeze - MINUTES_REGEX = /(\%m|\%mm|\%M|\%MM)/.freeze - SECONDS_REGEX = /(\%s|\%ss|\%S|\%SS)/.freeze + HOURS_REGEX = /(%h|%hh|%H|%HH)/.freeze + MINUTES_REGEX = /(%m|%mm|%M|%MM)/.freeze + SECONDS_REGEX = /(%s|%ss|%S|%SS)/.freeze OPERATIONS = %i[+ - * /].freeze attr_reader :data @@ -47,10 +47,10 @@ def set(value) ## => "-30:05" ## >> duration.to_s("%H*%M*%S") ## => "-30*05*03" - def to_s(string = '%H:%M:%S') + def to_s(string = "%H:%M:%S") text = string.dup - text['%'] = '-%' if text != '' && negative? + text["%"] = "-%" if text != "" && negative? text = text.gsub(HOURS_REGEX, format_number_abs(hours)) text = text.gsub(MINUTES_REGEX, format_number_abs(minutes)) @@ -60,7 +60,7 @@ def to_s(string = '%H:%M:%S') alias to_string to_s def format_number_abs(number) - format('%02d', number: number.to_i.abs) + format("%02d", number: number.to_i.abs) end def seconds @@ -95,12 +95,12 @@ def value_in_days def human [ - ('menos' if negative?), + ("menos" if negative?), "#{hours.abs} horas", "#{minutes.abs} minutos", - 'e', + "e", "#{seconds.abs} segundos" - ].compact.join(' ') + ].compact.join(" ") end def inspect diff --git a/lib/tempus/parser.rb b/lib/tempus/parser.rb index 856d58f..e8b35cd 100644 --- a/lib/tempus/parser.rb +++ b/lib/tempus/parser.rb @@ -28,13 +28,13 @@ def from_time end def from_string - str = @value.to_s.split(':') + str = @value.to_s.split(":") value = 0 %i[hours minutes seconds].each_with_index do |m, i| value += str.at(i).to_i.abs.send(m.to_s) end - str.to_s.include?('-') ? value * -1 : value + str.to_s.include?("-") ? value * -1 : value end end diff --git a/lib/tempus/version.rb b/lib/tempus/version.rb index 18112a2..b728a95 100644 --- a/lib/tempus/version.rb +++ b/lib/tempus/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true class Tempus - VERSION = '1.0.3' + VERSION = "1.1.0" end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7706d39..c1986bd 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,19 +1,16 @@ # frozen_string_literal: true -require 'bundler/setup' -require 'coveralls' -require 'simplecov' +require "simplecov" SimpleCov.start do - add_filter '/spec/' + add_filter "/spec/" end -Coveralls.wear! -require 'tempus' +require "tempus" RSpec.configure do |config| # Enable flags like --only-failures and --next-failure - config.example_status_persistence_file_path = '.rspec_status' + config.example_status_persistence_file_path = ".rspec_status" # Disable RSpec exposing methods globally on `Module` and `main` config.disable_monkey_patching! diff --git a/spec/tempus/tempus_helper_spec.rb b/spec/tempus/tempus_helper_spec.rb index 329d77e..960e1c4 100644 --- a/spec/tempus/tempus_helper_spec.rb +++ b/spec/tempus/tempus_helper_spec.rb @@ -3,29 +3,29 @@ RSpec.describe TempusHelper do let(:hours) { Tempus.new(30.hours + 5.minutes + 3.seconds) } let(:negative_hours) { Tempus.new(- 30.hours - 5.minutes - 3.seconds) } - let(:inspect_output) { '' } + let(:inspect_output) { "" } - it 'String to Tempus' do - expect('12:05:35'.to_tempus).to eq(Tempus.new(12.hours + 5.minutes + 35)) - expect('01:00:01'.to_tempus).to eq(Tempus.new(1.hours + 1.seconds)) - expect('30:5:3'.to_tempus).to eq(hours) - expect('-30:5:3'.to_tempus).to eq(negative_hours) + it "String to Tempus" do + expect("12:05:35".to_tempus).to eq(Tempus.new(12.hours + 5.minutes + 35)) + expect("01:00:01".to_tempus).to eq(Tempus.new(1.hours + 1.seconds)) + expect("30:5:3".to_tempus).to eq(hours) + expect("-30:5:3".to_tempus).to eq(negative_hours) end - it 'Number to Tempus' do - expect(3723.to_tempus.to_s).to eq('01:02:03') + it "Number to Tempus" do + expect(3723.to_tempus.to_s).to eq("01:02:03") expect(3723.to_tempus.inspect).to eq(inspect_output) end - it 'Float to Tempus' do - expect(3723.0.to_tempus.to_string).to eq('01:02:03') + it "Float to Tempus" do + expect(3723.0.to_tempus.to_string).to eq("01:02:03") end - it 'Time to Tempus' do - expect(Time.parse('2014-01-01 01:02:03').to_tempus.to_i).to eq(3723) + it "Time to Tempus" do + expect(Time.parse("2014-01-01 01:02:03").to_tempus.to_i).to eq(3723) end - it 'nil to Tempus' do + it "nil to Tempus" do expect(nil.to_tempus.data).to eq(0) end end diff --git a/spec/tempus_spec.rb b/spec/tempus_spec.rb index 8285f7f..7e66042 100644 --- a/spec/tempus_spec.rb +++ b/spec/tempus_spec.rb @@ -1,98 +1,98 @@ # frozen_string_literal: true RSpec.describe Tempus do - let(:hours) { Tempus.new(30.hours + 5.minutes + 3.seconds) } - let(:negative_hours) { Tempus.new(- 30.hours - 5.minutes - 3.seconds) } + let(:hours) { described_class.new(30.hours + 5.minutes + 3.seconds) } + let(:negative_hours) { described_class.new(- 30.hours - 5.minutes - 3.seconds) } - it 'has a version number' do - expect(Tempus::VERSION).not_to be nil + it "has a version number" do + expect(Tempus::VERSION).not_to be_nil end - it 'validates the object creation' do - expect(hours).to be_instance_of(Tempus) - expect(negative_hours).to be_instance_of(Tempus) + it "validates the object creation" do + expect(hours).to be_instance_of(described_class) + expect(negative_hours).to be_instance_of(described_class) end - it 'set value' do + it "set value" do expect(hours.set(125)).to eq(125.0) expect(hours.set(Time.now.midnight)).to eq(0.0) - expect(hours.to_s).to eq('00:00:00') - expect(hours.to_s('%M:%S')).to eq('00:00') + expect(hours.to_s).to eq("00:00:00") + expect(hours.to_s("%M:%S")).to eq("00:00") midnight = Time.now.midnight - expect(Tempus.new(0, only_hours: false).set(midnight)).to eq(midnight.to_i) + expect(described_class.new(0, only_hours: false).set(midnight)).to eq(midnight.to_i) end - it 'test output' do - expect(hours.respond_to?('to_s')).to eq(true) - expect(hours.to_s('')).to eq('') - expect(hours.to_s).to eq('30:05:03') - expect(hours.to_s('%H')).to eq('30') - expect(hours.to_s('%M')).to eq('05') - expect(hours.to_s('%S')).to eq('03') - expect(hours.to_s('%Mdakhdkj$#')).to eq('05dakhdkj$#') - expect(hours.to_s('Duration: %H:%M')).to eq('Duration: 30:05') - expect(hours.to_s('%H:%M:%S')).to eq('30:05:03') - expect(negative_hours.to_s('')).to eq('') - expect(negative_hours.to_s).to eq('-30:05:03') - expect(negative_hours.to_s('%H')).to eq('-30') - expect(negative_hours.to_s('%M')).to eq('-05') - expect(negative_hours.to_s('%S')).to eq('-03') - expect(negative_hours.to_s('%Mdakhdkj$#')).to eq('-05dakhdkj$#') - expect(negative_hours.to_s('Duration: %H:%M')).to eq('Duration: -30:05') - expect(negative_hours.to_s('%H:%M:%S')).to eq('-30:05:03') - expect(hours.human).to eq('30 horas 5 minutos e 3 segundos') - expect(negative_hours.human).to eq('menos 30 horas 5 minutos e 3 segundos') - expect(hours.positive?).to eq(true) - expect(hours.negative?).to eq(false) - expect(negative_hours.positive?).to eq(false) - expect(negative_hours.negative?).to eq(true) + it "test output" do + expect(hours.respond_to?(:to_s)).to be(true) + expect(hours.to_s("")).to eq("") + expect(hours.to_s).to eq("30:05:03") + expect(hours.to_s("%H")).to eq("30") + expect(hours.to_s("%M")).to eq("05") + expect(hours.to_s("%S")).to eq("03") + expect(hours.to_s("%Mdakhdkj$#")).to eq("05dakhdkj$#") + expect(hours.to_s("Duration: %H:%M")).to eq("Duration: 30:05") + expect(hours.to_s("%H:%M:%S")).to eq("30:05:03") + expect(negative_hours.to_s("")).to eq("") + expect(negative_hours.to_s).to eq("-30:05:03") + expect(negative_hours.to_s("%H")).to eq("-30") + expect(negative_hours.to_s("%M")).to eq("-05") + expect(negative_hours.to_s("%S")).to eq("-03") + expect(negative_hours.to_s("%Mdakhdkj$#")).to eq("-05dakhdkj$#") + expect(negative_hours.to_s("Duration: %H:%M")).to eq("Duration: -30:05") + expect(negative_hours.to_s("%H:%M:%S")).to eq("-30:05:03") + expect(hours.human).to eq("30 horas 5 minutos e 3 segundos") + expect(negative_hours.human).to eq("menos 30 horas 5 minutos e 3 segundos") + expect(hours.positive?).to be(true) + expect(hours.negative?).to be(false) + expect(negative_hours.positive?).to be(false) + expect(negative_hours.negative?).to be(true) end - it 'plus' do - expect(hours.respond_to?(:+)).to eq(true) + it "plus" do + expect(hours.respond_to?(:+)).to be(true) [ - ['00:01:00', '30:06:03'], - [1, '30:05:04'], - [negative_hours, '00:00:00'], - [1.hours, '31:05:03'], - [5.hours, '35:05:03'], - [1.minutes, '30:06:03'], - [nil, '30:05:03'] + ["00:01:00", "30:06:03"], + [1, "30:05:04"], + [negative_hours, "00:00:00"], + [1.hours, "31:05:03"], + [5.hours, "35:05:03"], + [1.minutes, "30:06:03"], + [nil, "30:05:03"] ].each { |value, expected| expect((hours + value).to_s).to eq(expected) } end - it 'minus' do - expect(hours.respond_to?(:-)).to eq(true) + it "minus" do + expect(hours.respond_to?(:-)).to be(true) [ - ['00:01:00', '30:04:03'], - [1, '30:05:02'], - [1.minutes, '30:04:03'], - [1.hours, '29:05:03'], - [5.hours, '25:05:03'], - [nil, '30:05:03'], - [negative_hours, '60:10:06'] + ["00:01:00", "30:04:03"], + [1, "30:05:02"], + [1.minutes, "30:04:03"], + [1.hours, "29:05:03"], + [5.hours, "25:05:03"], + [nil, "30:05:03"], + [negative_hours, "60:10:06"] ].each { |value, expected| expect((hours - value).to_s).to eq(expected) } end - it 'multiplication' do - expect(hours.respond_to?(:*)).to eq(true) + it "multiplication" do + expect(hours.respond_to?(:*)).to be(true) - expect(hours * 2).to eq('60:10:06'.to_tempus) - expect('10:00:00'.to_tempus * 0.5).to eq('5:00:00'.to_tempus) + expect(hours * 2).to eq("60:10:06".to_tempus) + expect("10:00:00".to_tempus * 0.5).to eq("5:00:00".to_tempus) end - it 'division' do - expect(hours.respond_to?(:/)).to eq(true) + it "division" do + expect(hours.respond_to?(:/)).to be(true) - expect((hours / 0.5).to_s).to eq('60:10:06') - expect((hours / 2).to_s).to eq('15:02:31') + expect((hours / 0.5).to_s).to eq("60:10:06") + expect((hours / 2).to_s).to eq("15:02:31") end - it 'validates the value in methods' do + it "validates the value in methods" do expect(1.day.to_tempus.value_in_days).to eq(1) expect(1.day.to_tempus.to_xls_time).to eq(1) expect(2.hours.to_tempus.value_in_hours).to eq(2) diff --git a/tempus.gemspec b/tempus.gemspec index 6886197..902d0cb 100644 --- a/tempus.gemspec +++ b/tempus.gemspec @@ -1,36 +1,38 @@ # frozen_string_literal: true -require_relative 'lib/tempus/version' +require_relative "lib/tempus/version" Gem::Specification.new do |spec| - spec.name = 'tempus' - spec.version = Tempus::VERSION - spec.authors = ['Danilo Jeremias da Silva'] - spec.email = ['daniloj.dasilva@gmail.com'] + spec.name = "tempus" + spec.version = Tempus::VERSION + spec.authors = ["Danilo Jeremias da Silva"] + spec.email = ["daniloj.dasilva@gmail.com"] - spec.summary = 'Gem to efficiently manipulate the time.' - spec.description = <<-DESCRIPTION + spec.summary = "Gem to efficiently manipulate the time." + spec.description = <<-DESCRIPTION Gem to efficiently manipulate the time. Adding, subtracting and converting more than 24 hours easy.' DESCRIPTION - spec.homepage = 'https://github.com/dannnylo/tempus' - spec.license = 'MIT' - spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0') + spec.homepage = "https://github.com/dannnylo/tempus" + spec.license = "MIT" + spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0") - spec.metadata['homepage_uri'] = spec.homepage - spec.metadata['source_code_uri'] = spec.homepage + spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["source_code_uri"] = spec.homepage - spec.files = Dir.chdir(File.expand_path(__dir__)) do - `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } + # Specify which files should be added to the gem when it is released. + # The `git ls-files -z` loads the files in the RubyGem that have been added into git. + spec.files = Dir.chdir(__dir__) do + `git ls-files -z`.split("\x0").reject do |f| + (File.expand_path(f) == __FILE__) || + f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile]) + end end - spec.bindir = 'exe' - spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } - spec.require_paths = ['lib'] - spec.add_runtime_dependency 'activesupport', '> 5' - spec.add_development_dependency 'bundler', '~> 2.1' - spec.add_development_dependency 'coveralls', '~> 0.8' - spec.add_development_dependency 'rake', '~> 13.0' - spec.add_development_dependency 'rspec', '~> 3.9' - spec.add_development_dependency 'simplecov', '~> 0.9' + spec.bindir = "exe" + spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } + spec.require_paths = ["lib"] + + spec.add_runtime_dependency "activesupport", "> 5" + spec.metadata["rubygems_mfa_required"] = "true" end From 28177fd42dc33a4bff432db5c48870f411b34c03 Mon Sep 17 00:00:00 2001 From: Danilo Jeremias da Silva Date: Sat, 30 Sep 2023 23:58:57 -0300 Subject: [PATCH 2/2] Fix readme --- README.md | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 95b7560..cf7f630 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,52 @@ # Tempus -TODO: Delete this and the text below, and describe your gem + + Gem Version + -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/tempus`. To experiment with that code, run `bin/console` for an interactive prompt. +Gem to efficiently manipulate the time, adding, subtracting and converting hours. ## Installation -TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org. - Install the gem and add to the application's Gemfile by executing: - $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG + $ bundle add tempus If bundler is not being used to manage dependencies, install the gem by executing: - $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG + $ gem install tempus ## Usage -TODO: Write usage instructions here +With this gem you can manage durations of time. + +### Initialize with duration +```ruby + hours = Tempus.new(30.hours + 5.minutes + 3.seconds) + => + hours.value_in_minutes + => 1805.05 + hours.to_s("%H hours and %M minutes") + => "30 hours and 05 minutes" +``` +### Convert from other types +```ruby + hours = "35:05:01".to_tempus + => + hours + 6.hours + => +``` +```ruby + Tempus.new(Time.now) + => +``` + +### Sum durations + +```ruby + "1:00:00".to_tempus + "2:00" + => +``` ## Development