due_summary 1.0.1

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: e0a098d668f78251fb98c10c4a23bbf4db8629dbd8461be87b3e7b2515b8e472
4
+ data.tar.gz: cef5fbe6a73f34acc4e4d8b822c7485fa66364677c33cf56934832ac0831be01
5
+ SHA512:
6
+ metadata.gz: a205742f2600d648d8169de7e87cf4ad04fd12e57965c50af6befcb7e1be7a1c5c5ea1eef3bdbe7f286f4d7880a0fa81f12af10797b823449887541a251f33e6
7
+ data.tar.gz: 504a4389011b256567b33883d2e172c71e379d4ad388f0e552b82b3becb20f98d77b7789c53b8af5aab3807e89845f6861cb6105b7d0b2ec457281591c1dd706
data/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) <year> <copyright holders>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ ************ Due Summary Intro ************
@@ -0,0 +1,19 @@
1
+ # Bring in a special type of rake task to run tests
2
+ require 'rake/testtask'
3
+ # Bring in a special type of rake task to generate rdocs
4
+ require 'rdoc/task'
5
+
6
+ # When we run rake, run our test
7
+ task default: 'test'
8
+
9
+ # Definition of our test task
10
+ Rake::TestTask.new do |task|
11
+ task.pattern = 'test/test*.rb'
12
+ end
13
+
14
+ # Definition of our rdoc generate task
15
+ RDoc::Task.new do |rdoc|
16
+ rdoc.main = "README.rdoc"
17
+ rdoc.rdoc_files.include("README.rdoc", "lib/*")
18
+ rdoc.rdoc_dir = 'doc'
19
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'due_summary'
4
+ due = Due::DueSummary.new(ARGV[0])
5
+ due.summary_table
@@ -0,0 +1,30 @@
1
+ # Gem specification file for duesummary gem
2
+ require_relative 'lib/due_summary/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ # Required attributes:
6
+ s.name = 'due_summary'
7
+ s.version = Due::VERSION
8
+ s.summary = 'Due summary for a given date!'
9
+ s.authors = ['Rag Dhiman']
10
+ s.files = ['LICENSE', 'README.rdoc', 'Rakefile', 'due_summary.gemspec', 'lib/due_summary.rb', 'lib/due_summary/duetext.rb', 'test/testduesummary.rb']
11
+ # Additional attributes that are recommended:
12
+ s.description = 'Due summary for a given date including months, days and years till the date!'
13
+ s.email = 'rubycoder@example.com'
14
+ s.homepage = 'https://rubygems.org/gems/example'
15
+ s.licenses = ['MIT']
16
+ s.metadata = {
17
+ 'source_code_uri' => 'https://github.com/RagDhiman/PS-DueSummaryGem-RubyGems-',
18
+ "bug_tracker_uri" => "https://github.com/RagDhiman/PS-DueSummaryGem-RubyGems-/issues",
19
+ "changelog_uri" => "https://github.com/RagDhiman/PS-DueSummaryGem-RubyGems-/branches/all",
20
+ "documentation_uri" => "https://github.com/RagDhiman/PS-DueSummaryGem-RubyGems-/tree/master",
21
+ "homepage_uri" => "https://www.pluralsight.com/authors/rag-dhiman",
22
+ "mailing_list_uri" => "https://www.pluralsight.com/authors/rag-dhiman",
23
+ "wiki_uri" => "https://github.com/RagDhiman/PS-DueSummaryGem-RubyGems-/wiki"
24
+ }
25
+ # Dependency information:
26
+ s.add_runtime_dependency 'colorize', '~> 0.8.1'
27
+ s.add_development_dependency 'minitest', '~> 5.14.1'
28
+ s.add_runtime_dependency 'tabulate', '~> 0.1.2'
29
+ s.executables << 'due_summary'
30
+ end
@@ -0,0 +1,110 @@
1
+ require 'time'
2
+ require 'tabulate'
3
+ require_relative 'due_summary/duetext'
4
+
5
+ # The due module contains all classes and data to provide due-summary functionality.
6
+ module Due
7
+ # The due class takes a given date and provides several period measures until or since that date.
8
+ class DueSummary
9
+
10
+ # Date time field set via the constructor, and the date-time value the due summary stats are based around.
11
+ attr_accessor :date_time
12
+ # Date time field used to store the current date-time used as part of the due summary calculations.
13
+ attr_accessor :now_date_time
14
+ # The numeric field used to store the time difference between the provided date and the current date and time.
15
+ attr_accessor :difference
16
+
17
+ # Class constructor that takes in a DateTime argument to base the due-summary stats on.
18
+ def initialize(the_date_time)
19
+ @date_time = Time.parse(the_date_time)
20
+ @difference = 0.0
21
+ end
22
+
23
+ # Uses the puts command to output all the due-summary stats as a line separated text.
24
+ def print_summary
25
+ update_now_date_time
26
+ calc_difference
27
+ puts "#{DueText.minutes} #{till_or_since}: \t #{calc_mins_till.round(2)} #{DueText.minutes_suffix} \n
28
+ #{DueText.hours} #{till_or_since}: \t #{calc_hours_till.round(2)} #{DueText.hours_suffix} \n
29
+ #{DueText.days} #{till_or_since}: \t #{calc_days_till.round(2)} #{DueText.days_suffix} \n
30
+ #{DueText.weeks} #{till_or_since}: \t #{calc_weeks_till.round(2)} #{DueText.weeks_suffix} \n
31
+ #{DueText.months} #{till_or_since}: \t #{calc_months_till.round(2)} #{DueText.months_suffix} \n
32
+ #{DueText.years} #{till_or_since}: \t #{calc_years_till.round(2)} #{DueText.years_suffix}"
33
+ end
34
+
35
+ # This method returns an array containing the due-summary stats.
36
+ def summary_array
37
+ row = []
38
+ column = [DueText.minutes, till_or_since, calc_mins_till.round(2), DueText.minutes_suffix]
39
+ row << column
40
+ column = [DueText.hours, till_or_since, calc_hours_till.round(2), DueText.hours_suffix]
41
+ row << column
42
+ column = [DueText.days, till_or_since, calc_days_till.round(2), DueText.days_suffix]
43
+ row << column
44
+ column = [DueText.weeks, till_or_since, calc_weeks_till.round(2), DueText.weeks_suffix]
45
+ row << column
46
+ column = [DueText.months, till_or_since, calc_months_till.round(2), DueText.months_suffix]
47
+ row << column
48
+ column = [DueText.years, till_or_since, calc_years_till.round(2), DueText.years_suffix]
49
+ row << column
50
+ end
51
+
52
+ # This method uses the puts command to output all the due-summary stats as a formatted table.
53
+ def summary_table
54
+ update_now_date_time
55
+ calc_difference
56
+ labels = [DueText.period, ' ', DueText.duration, DueText.measure]
57
+ rows = summary_array
58
+ puts tabulate(labels, rows, { 'indent' => 4, 'style' => 'fancy' })
59
+ end
60
+
61
+ # This method updates the current date and time regarded as the now current date and time for the due-summary stats.
62
+ def update_now_date_time
63
+ @now_date_time = Time.new
64
+ end
65
+
66
+ # This method calculates the due summary time difference between the provided date and the now date.
67
+ def calc_difference
68
+ @difference = @date_time.to_f - @now_date_time.to_f
69
+ end
70
+
71
+ # This method returns 'since' or 'till' as a description to describe the time difference.
72
+ def till_or_since
73
+ if @difference.negative?
74
+ DueText.since
75
+ else
76
+ DueText.till
77
+ end
78
+ end
79
+
80
+ # This method calculates the due-summary time difference in minutes.
81
+ def calc_mins_till
82
+ (@difference.round(2) / 60.00).round(2)
83
+ end
84
+
85
+ # This method calculates the due-summary time difference in hours.
86
+ def calc_hours_till
87
+ (calc_mins_till / 60.00).round(2)
88
+ end
89
+
90
+ # This method calculates the due-summary time difference in days.
91
+ def calc_days_till
92
+ (calc_hours_till / 24.00).round(2)
93
+ end
94
+
95
+ # This method calculates the due-summary time difference in months.
96
+ def calc_months_till
97
+ (calc_days_till / 31.0).round(2)
98
+ end
99
+
100
+ # This method calculates the due-summary time difference in years.
101
+ def calc_years_till
102
+ (calc_months_till / 12.00).round(2)
103
+ end
104
+
105
+ # This method calculates the due-summary time difference in weeks.
106
+ def calc_weeks_till
107
+ (calc_days_till / 7.0).round(2)
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,74 @@
1
+ # The due module contains all classes and data to provide due-summary functionality.
2
+ module Due
3
+ # The dueText class provides all the text for the due-summary functionality.
4
+ class DueText
5
+ # Method provides text for minutes measure name.
6
+ def self.minutes
7
+ 'Minutes'
8
+ end
9
+ # Method provides text for hours measure name.
10
+ def self.hours
11
+ 'Hours'
12
+ end
13
+ # Method provides text for days measure name.
14
+ def self.days
15
+ 'Days'
16
+ end
17
+ # Method provides text for weeks measure name.
18
+ def self.weeks
19
+ 'Weeks'
20
+ end
21
+ # Method provides text for months measure name.
22
+ def self.months
23
+ 'Months'
24
+ end
25
+ # Method provides text for years measure name.
26
+ def self.years
27
+ 'Years'
28
+ end
29
+ # Method provides text for minutes suffix for a messure.
30
+ def self.minutes_suffix
31
+ 'min(s)'
32
+ end
33
+ # Method provides text for hours suffix for a messure.
34
+ def self.hours_suffix
35
+ 'hours(s)'
36
+ end
37
+ # Method provides text for days suffix for a messure.
38
+ def self.days_suffix
39
+ 'day(s)'
40
+ end
41
+ # Method provides text for weeks suffix for a messure.
42
+ def self.weeks_suffix
43
+ 'week(s)'
44
+ end
45
+ # Method provides text for months suffix for a messure.
46
+ def self.months_suffix
47
+ 'month(s)'
48
+ end
49
+ # Method provides text for years suffix for a messure.
50
+ def self.years_suffix
51
+ 'year(s)'
52
+ end
53
+ # Method provides text for period.
54
+ def self.period
55
+ 'Period'
56
+ end
57
+ # Method provides text for duration.
58
+ def self.duration
59
+ 'Duration'
60
+ end
61
+ # Method provides text for measure.
62
+ def self.measure
63
+ 'Measure'
64
+ end
65
+ # Method provides text for since.
66
+ def self.since
67
+ 'since'
68
+ end
69
+ # Method provides text for till.
70
+ def self.till
71
+ 'till'
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,69 @@
1
+ require 'minitest/autorun'
2
+ require_relative '../lib/due_summary'
3
+
4
+ class TestDue < Minitest::Test
5
+
6
+ def test_due_difference_seconds_between_dates
7
+ due = Due::DueSummary.new('2020-10-11 12:00:00')
8
+ due.now_date_time = Time.parse('2020-10-12 12:00:00')
9
+ due.calc_difference
10
+
11
+ assert_equal(-86_400.0, due.difference)
12
+ end
13
+
14
+ def test_due_difference_minutes_between_dates
15
+ due = Due::DueSummary.new('2020-10-11 12:00:00')
16
+ due.now_date_time = Time.parse('2020-10-12 12:00:00')
17
+ due.calc_difference
18
+
19
+ assert_equal(-1440, due.calc_mins_till)
20
+ end
21
+
22
+ def test_due_difference_hours_between_dates
23
+ due = Due::DueSummary.new('2020-10-11 12:00:00')
24
+ due.now_date_time = Time.parse('2020-10-12 12:00:00')
25
+ due.calc_difference
26
+
27
+ assert_equal(-24, due.calc_hours_till)
28
+ end
29
+
30
+ def test_due_difference_days_between_dates
31
+ due = Due::DueSummary.new('2020-10-11 12:00:00')
32
+ due.now_date_time = Time.parse('2020-10-12 12:00:00')
33
+ due.calc_difference
34
+
35
+ assert_equal(-1, due.calc_days_till)
36
+ end
37
+
38
+ def test_due_difference_days_between_dates
39
+ due = Due::DueSummary.new('2020-10-11 12:00:00')
40
+ due.now_date_time = Time.parse('2020-10-12 12:00:00')
41
+ due.calc_difference
42
+
43
+ assert_equal(-1, due.calc_days_till)
44
+ end
45
+
46
+ def test_due_difference_months_between_dates
47
+ due = Due::DueSummary.new('2020-07-01 00:00:00')
48
+ due.now_date_time = Time.parse('2020-08-01 00:00:00')
49
+ due.calc_difference
50
+
51
+ assert_equal(-1, due.calc_months_till)
52
+ end
53
+
54
+ def test_due_difference_years_between_dates
55
+ due = Due::DueSummary.new('2019-07-01 00:00:00')
56
+ due.now_date_time = Time.parse('2020-07-02 00:00:00')
57
+ due.calc_difference
58
+
59
+ assert(due.calc_years_till >= -0.99)
60
+ end
61
+
62
+ def test_due_difference_weeks_between_dates
63
+ due = Due::DueSummary.new('2020-07-01 00:00:00')
64
+ due.now_date_time = Time.parse('2020-08-01 00:00:00')
65
+ due.calc_difference
66
+
67
+ assert(-4.43, due.calc_weeks_till)
68
+ end
69
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: due_summary
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rag Dhiman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-08-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 5.14.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 5.14.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: tabulate
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.2
55
+ description: Due summary for a given date including months, days and years till the
56
+ date!
57
+ email: rubycoder@example.com
58
+ executables:
59
+ - due_summary
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - LICENSE
64
+ - README.rdoc
65
+ - Rakefile
66
+ - bin/due_summary
67
+ - due_summary.gemspec
68
+ - lib/due_summary.rb
69
+ - lib/due_summary/duetext.rb
70
+ - test/testduesummary.rb
71
+ homepage: https://rubygems.org/gems/example
72
+ licenses:
73
+ - MIT
74
+ metadata:
75
+ source_code_uri: https://github.com/RagDhiman/PS-DueSummaryGem-RubyGems-
76
+ bug_tracker_uri: https://github.com/RagDhiman/PS-DueSummaryGem-RubyGems-/issues
77
+ changelog_uri: https://github.com/RagDhiman/PS-DueSummaryGem-RubyGems-/branches/all
78
+ documentation_uri: https://github.com/RagDhiman/PS-DueSummaryGem-RubyGems-/tree/master
79
+ homepage_uri: https://www.pluralsight.com/authors/rag-dhiman
80
+ mailing_list_uri: https://www.pluralsight.com/authors/rag-dhiman
81
+ wiki_uri: https://github.com/RagDhiman/PS-DueSummaryGem-RubyGems-/wiki
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubygems_version: 3.1.3
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Due summary for a given date!
101
+ test_files: []