thirsty 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 881ac746766996a9a620dafd02a5bb1b5daee9d5f34abfb27b173074d3612782
4
+ data.tar.gz: 87f65e19e566a09fef14bc375f13af1f70a6630266ccf53f0fceb1d0b3098153
5
+ SHA512:
6
+ metadata.gz: fd43c22a396040be8ad22a4585b9b298d7379b9c256585aec967f9d259c9b7a122c2aa80bb5505b7e58269261a5ecb48f7df1569b742afe19b7d7a79ed6167a3
7
+ data.tar.gz: 7492e0994d6b4dbf88db04dcb153d63af67e7cf07e943a3307dab7eea736b82be8a87575ac73295bbb31f04bc2ac0a37a2d061897ec871316f41078a2802dc8e
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,42 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Exclude:
5
+ - 'bin/**/*'
6
+ - 'db/*schema.rb'
7
+ - 'db/seeds.rb'
8
+ - 'db/migrate/*'
9
+ - 'tmp/**/*'
10
+ - 'vendor/**/*'
11
+ - 'frontend/**/*'
12
+
13
+ Layout/LineLength:
14
+ Max: 125
15
+ Exclude:
16
+ - 'spec/**/*_spec.rb'
17
+
18
+ Metrics/AbcSize:
19
+ Exclude:
20
+ - db/migrate/*.rb
21
+
22
+ Metrics/BlockLength:
23
+ Exclude:
24
+ - app/schemas/**/*schema.rb
25
+ - config/routes.rb
26
+ - spec/**/*.rb
27
+
28
+ Metrics/MethodLength:
29
+ Exclude:
30
+ - db/migrate/*.rb
31
+
32
+ Naming/RescuedExceptionsVariableName:
33
+ PreferredName: exception
34
+
35
+ Style/Documentation:
36
+ Enabled: false
37
+
38
+ Style/TrailingUnderscoreVariable:
39
+ Enabled: false
40
+
41
+ Style/GuardClause:
42
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in thirsty.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 12.0'
9
+ gem 'rubocop'
10
+ gem 'solargraph'
@@ -0,0 +1,64 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ thirsty (0.1.0)
5
+ thor (~> 1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.0)
11
+ backport (1.1.2)
12
+ benchmark (0.1.0)
13
+ e2mmap (0.1.0)
14
+ jaro_winkler (1.5.4)
15
+ maruku (0.7.3)
16
+ mini_portile2 (2.4.0)
17
+ nokogiri (1.10.9)
18
+ mini_portile2 (~> 2.4.0)
19
+ parallel (1.19.1)
20
+ parser (2.7.1.2)
21
+ ast (~> 2.4.0)
22
+ rainbow (3.0.0)
23
+ rake (12.3.3)
24
+ reverse_markdown (1.4.0)
25
+ nokogiri
26
+ rexml (3.2.4)
27
+ rubocop (0.83.0)
28
+ parallel (~> 1.10)
29
+ parser (>= 2.7.0.1)
30
+ rainbow (>= 2.2.2, < 4.0)
31
+ rexml
32
+ ruby-progressbar (~> 1.7)
33
+ unicode-display_width (>= 1.4.0, < 2.0)
34
+ ruby-progressbar (1.10.1)
35
+ solargraph (0.39.7)
36
+ backport (~> 1.1)
37
+ benchmark
38
+ bundler (>= 1.17.2)
39
+ e2mmap
40
+ jaro_winkler (~> 1.5)
41
+ maruku (~> 0.7, >= 0.7.3)
42
+ nokogiri (~> 1.9, >= 1.9.1)
43
+ parser (~> 2.3)
44
+ reverse_markdown (~> 1.0, >= 1.0.5)
45
+ rubocop (~> 0.52)
46
+ thor (~> 1.0)
47
+ tilt (~> 2.0)
48
+ yard (~> 0.9, >= 0.9.24)
49
+ thor (1.0.1)
50
+ tilt (2.0.10)
51
+ unicode-display_width (1.7.0)
52
+ yard (0.9.25)
53
+
54
+ PLATFORMS
55
+ ruby
56
+
57
+ DEPENDENCIES
58
+ rake (~> 12.0)
59
+ rubocop
60
+ solargraph
61
+ thirsty!
62
+
63
+ BUNDLED WITH
64
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Paweł J. Wal
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,41 @@
1
+ # Thirsty
2
+
3
+ A quick and dirty command to track your water intake on the CLI.
4
+
5
+ ## Installation
6
+
7
+ Install it for your CLI with:
8
+
9
+ $ gem install thirsty
10
+
11
+ Then set your daily water requirement with:
12
+
13
+ ```
14
+ $ thirsty update_requirement 2.5
15
+ ```
16
+ ## Usage
17
+
18
+ Note drinking some water with:
19
+
20
+ ```
21
+ $ thirsty add 1.5 # liters
22
+ $ thirsty add 330 # will automatically consider values higher than 3 to be milliliters
23
+ ```
24
+ Check how you're doing with:
25
+ ```
26
+ $ thirsty today
27
+ ```
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bundle install` to install dependencies.
32
+ 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).
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/thirsty.
37
+
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ task default: :spec
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'thirsty'
5
+
6
+ Thirsty::Cli.start(ARGV)
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thor'
4
+ require 'thirsty/base'
5
+
6
+ module Thirsty; end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'version'
4
+ require_relative 'callable'
5
+ require_relative 'cli'
6
+
7
+ module Thirsty
8
+ autoload :Requirement, File.expand_path('requirement', __dir__)
9
+ autoload :Today, File.expand_path('today', __dir__)
10
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Thirsty
4
+ class Callable
5
+ def self.call(*args)
6
+ new(*args).call
7
+ end
8
+
9
+ # @abstract Subclass is expected to implement #call
10
+ # @!method call
11
+ end
12
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thor'
4
+
5
+ module Thirsty
6
+ class Cli < Thor
7
+ desc 'update_requirement REQUIREMENT', 'sets your required intake to REQUIREMENT liters'
8
+ def update_requirement(requirement)
9
+ Requirement::Update.call(requirement)
10
+ rescue ArgumentError
11
+ puts "The value #{requirement} does not look like a valid number."
12
+ exit 1
13
+ end
14
+
15
+ desc 'requirement', 'get your current required intake'
16
+ def requirement
17
+ puts "#{Requirement::Get.call}L"
18
+ rescue Errno::ENOENT
19
+ puts 'Please set your requirement first.'
20
+ exit 1
21
+ end
22
+
23
+ desc 'today', 'get your today intake'
24
+ def today
25
+ requirement = Requirement::Get.call
26
+ today = Today::Get.call
27
+ percentage = (today / requirement * 100).to_i
28
+ puts "#{today} / #{requirement} (#{percentage}%)"
29
+ rescue Errno::ENOENT
30
+ puts 'Please set your requirement first.'
31
+ exit 1
32
+ end
33
+
34
+ desc 'add AMOUNT', 'add AMOUNT to your current intake'
35
+ def add(amount)
36
+ Today::Add.call(amount)
37
+ rescue ArgumentError
38
+ puts "The value #{amount} does not look like a valid number."
39
+ exit 1
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'requirement/update'
4
+ require_relative 'requirement/get'
5
+
6
+ module Thirsty
7
+ module Requirement; end
8
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Thirsty
4
+ module Requirement
5
+ class Get < Callable
6
+ def call
7
+ File.read(File.expand_path('~/.thirsty/requirement.txt')).to_f || '0.0'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+
5
+ module Thirsty
6
+ module Requirement
7
+ class Update < Callable
8
+ def initialize(requirement)
9
+ @requirement = requirement
10
+ end
11
+
12
+ def call
13
+ validate_input
14
+ ensure_directory
15
+ write_requirement
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :requirement
21
+
22
+ def validate_input
23
+ if requirement !~ /^\s*[+-]?((\d+_?)*\d+(\.(\d+_?)*\d+)?|\.(\d+_?)*\d+)(\s*|([eE][+-]?(\d+_?)*\d+)\s*)$/
24
+ raise ArgumentError, "invalid value for Float(): #{requirement.inspect}"
25
+ end
26
+ end
27
+
28
+ def ensure_directory
29
+ FileUtils.mkdir_p(File.expand_path('~/.thirsty'))
30
+ end
31
+
32
+ def write_requirement
33
+ File.open(File.expand_path('~/.thirsty/requirement.txt'), 'w+') { |f| f << requirement.to_f }
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'today/get'
4
+ require_relative 'today/add'
5
+
6
+ module Thirsty
7
+ module Today; end
8
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+
5
+ module Thirsty
6
+ module Today
7
+ class Add < Callable
8
+ def initialize(amount)
9
+ @amount = amount
10
+ end
11
+
12
+ def call
13
+ validate_amount
14
+ update_amount
15
+ end
16
+
17
+ private
18
+
19
+ attr_reader :amount
20
+
21
+ def validate_amount
22
+ if amount !~ /^\s*[+-]?((\d+_?)*\d+(\.(\d+_?)*\d+)?|\.(\d+_?)*\d+)(\s*|([eE][+-]?(\d+_?)*\d+)\s*)$/
23
+ raise ArgumentError, "invalid value for Float(): #{requirement.inspect}"
24
+ end
25
+ end
26
+
27
+ def normalized_amount
28
+ amount_f = amount.to_f
29
+ amount_f < 3 ? amount_f : amount_f / 1000
30
+ end
31
+
32
+ def current
33
+ @current ||= Get.call
34
+ end
35
+
36
+ def update_amount
37
+ full_amount = current + normalized_amount
38
+ File.open(File.expand_path("~/.thirsty/#{Date.today}.txt"), 'w+') { |f| f << full_amount }
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+
5
+ module Thirsty
6
+ module Today
7
+ class Get < Callable
8
+ def call
9
+ return 0.0 unless file_exists?
10
+
11
+ today
12
+ end
13
+
14
+ private
15
+
16
+ def file_path
17
+ @file_path ||= File.expand_path("~/.thirsty/#{Date.today}.txt")
18
+ end
19
+
20
+ def file_exists?
21
+ File.exist?(file_path)
22
+ end
23
+
24
+ def today
25
+ File.read(file_path).to_f
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Thirsty
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/thirsty/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'thirsty'
7
+ spec.version = Thirsty::VERSION
8
+ spec.authors = ['Paweł J. Wal']
9
+ spec.email = ['p@paweljw.al']
10
+
11
+ spec.summary = 'A CLI tool to watch your water intake.'
12
+ spec.homepage = 'https://github.com/paweljw/thirsty'
13
+ spec.license = 'MIT'
14
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
15
+
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = 'https://github.com/paweljw/thirsty'
18
+
19
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|.rubocop.yml)/}) }
21
+ end
22
+ spec.bindir = 'exe'
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_runtime_dependency 'thor', '~> 1.0'
27
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thirsty
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Paweł J. Wal
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-05-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ description:
28
+ email:
29
+ - p@paweljw.al
30
+ executables:
31
+ - thirsty
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - ".rubocop.yml"
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - exe/thirsty
43
+ - lib/thirsty.rb
44
+ - lib/thirsty/base.rb
45
+ - lib/thirsty/callable.rb
46
+ - lib/thirsty/cli.rb
47
+ - lib/thirsty/requirement.rb
48
+ - lib/thirsty/requirement/get.rb
49
+ - lib/thirsty/requirement/update.rb
50
+ - lib/thirsty/today.rb
51
+ - lib/thirsty/today/add.rb
52
+ - lib/thirsty/today/get.rb
53
+ - lib/thirsty/version.rb
54
+ - thirsty.gemspec
55
+ homepage: https://github.com/paweljw/thirsty
56
+ licenses:
57
+ - MIT
58
+ metadata:
59
+ homepage_uri: https://github.com/paweljw/thirsty
60
+ source_code_uri: https://github.com/paweljw/thirsty
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.3.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.1.2
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: A CLI tool to watch your water intake.
80
+ test_files: []