hours_to_seconds 1.0.12

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of hours_to_seconds might be problematic. Click here for more details.

@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: acd97861b6b2bce83d65e8ff0eb3c9d6962d511475d31348efbe8e1a18ef900b
4
+ data.tar.gz: 2e93ec5856fd2cc2720534dc059c13957e55aba8c07cd50cdd54c9234517da18
5
+ SHA512:
6
+ metadata.gz: d07b5d655ba3ef095e1cb8f14f101a9b701770270c8ea8f588e9c16389dbc1ff65c38d42c144beece39c35cea433f446521a3b471dc280eecce0c358b8bc898c
7
+ data.tar.gz: 120003556e909523b37e47aca05ca043f09e046a25c79b938926a58902b0f64726fac8bdcca8942022201e0accc04833430befb1764b03730d77f9966be96c5a
@@ -0,0 +1,11 @@
1
+ = Usage of this Library
2
+
3
+ == Requiring it
4
+
5
+ require 'hours_to_seconds'
6
+
7
+ == Using it in a project
8
+
9
+ _ = HoursToSeconds.new("00:33:55")
10
+ _.run
11
+
@@ -0,0 +1,45 @@
1
+ # =========================================================================== #
2
+ # Gemspec for Project HoursToSeconds.
3
+ # =========================================================================== #
4
+ require 'hours_to_seconds'
5
+
6
+ Gem::Specification.new { |s|
7
+
8
+ s.name = 'hours_to_seconds'
9
+ s.version = HoursToSeconds::VERSION
10
+ s.date = Time.now.strftime('%Y-%m-%d')
11
+
12
+ s.summary = <<-EOF
13
+
14
+ If you have specific suggestions to make this gem more
15
+ useful for others, please drop me an email at:
16
+
17
+ shevegen@gmail.com
18
+
19
+ Thank you.
20
+
21
+ EOF
22
+
23
+ s.description = <<-EOF
24
+
25
+ This library is called hours_to_seconds.
26
+
27
+ EOF
28
+
29
+ s.extra_rdoc_files = %w()
30
+
31
+ s.authors = ['Robert A. Heiler']
32
+ s.email = 'shevegen@gmail.com'
33
+ s.files = Dir['**/*']
34
+ s.license = 'GPL-2.0'
35
+
36
+ s.homepage = 'http://rubygems.org/gems/hours_to_seconds'
37
+
38
+ s.required_ruby_version = '>= '+RUBY_VERSION
39
+ s.required_rubygems_version = '>= '+Gem::VERSION
40
+ s.rubygems_version = '>= '+Gem::VERSION
41
+
42
+ # Dependencies for this project
43
+ s.add_dependency 'colours'
44
+
45
+ }
@@ -0,0 +1 @@
1
+ require 'hours_to_seconds/hours_to_seconds.rb'
@@ -0,0 +1,165 @@
1
+ #!/System/Index/bin/ruby -w
2
+ # Encoding: ISO-8859-1
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === HoursToSeconds
6
+ #
7
+ # This class converts from a larger Duration format to the equivalent
8
+ # amount in seconds.
9
+ #
10
+ # Specific usage examples:
11
+ # HoursToSeconds['01:02:03.33']
12
+ # HoursToSeconds.new '01:02:03.33'
13
+ # =========================================================================== #
14
+ # require 'hours_to_seconds'
15
+ # =========================================================================== #
16
+ begin
17
+ require 'colours'
18
+ rescue LoadError; end
19
+ require 'hours_to_seconds/version/version.rb'
20
+
21
+ class HoursToSeconds # === HoursToSeconds
22
+
23
+ include Colours
24
+
25
+ # ========================================================================= #
26
+ # === initialize
27
+ # ========================================================================= #
28
+ def initialize(
29
+ i = nil,
30
+ run_already = true
31
+ )
32
+ reset
33
+ set_format(i)
34
+ case run_already
35
+ when :dont_run_yet, :do_not_run_yet
36
+ run_already = false
37
+ when :be_silent
38
+ run_already = true
39
+ @be_verbose = false
40
+ end
41
+ start_conversion
42
+ run if run_already
43
+ end
44
+
45
+ # ========================================================================= #
46
+ # === reset
47
+ # ========================================================================= #
48
+ def reset
49
+ @format = ''
50
+ @be_verbose = true
51
+ end
52
+
53
+ # ========================================================================= #
54
+ # === start_conversion
55
+ #
56
+ # This is called from the method run().
57
+ # It will set the ivar @n_seconds.
58
+ # ========================================================================= #
59
+ def start_conversion(i = @format) # also sets @splitted.
60
+ @splitted = i.split(':')
61
+ _ = @splitted[0].to_i * 60 * 60 # Add hours here.
62
+ _ += @splitted[1].to_i * 60 # Add minutes here.
63
+ _ += @splitted[2].to_i # Add Seconds here.
64
+ @n_seconds = _
65
+ end; alias convert start_conversion # === convert
66
+ alias process start_conversion # === process
67
+
68
+ # ========================================================================= #
69
+ # === n_milliseconds
70
+ # ========================================================================= #
71
+ def n_milliseconds
72
+ return @n_seconds.to_i * 1000
73
+ end
74
+
75
+ # ========================================================================= #
76
+ # === to_s
77
+ # ========================================================================= #
78
+ def to_s
79
+ result = sfancy(@format)+' sind '+simp(@n_seconds.to_s)+' Sekunden.'
80
+ return result
81
+ end
82
+
83
+ # ========================================================================= #
84
+ # === display_result
85
+ # ========================================================================= #
86
+ def display_result
87
+ e to_s if be_verbose? # Simply call to_s here, but only if we are verbose.
88
+ end; alias display display_result # === display
89
+ alias output display_result # === output
90
+ alias report display_result # === report
91
+
92
+ # ========================================================================= #
93
+ # == be_silent
94
+ # ========================================================================= #
95
+ def be_silent
96
+ @be_verbose = false
97
+ end
98
+
99
+ # ========================================================================= #
100
+ # === be_verbose?
101
+ # ========================================================================= #
102
+ def be_verbose?
103
+ @be_verbose
104
+ end
105
+
106
+ # ========================================================================= #
107
+ # === n_seconds?
108
+ # ========================================================================= #
109
+ def n_seconds?
110
+ @n_seconds
111
+ end; alias n_seconds n_seconds? # === n_seconds
112
+ alias seconds n_seconds? # === seconds
113
+
114
+ # ========================================================================= #
115
+ # === set_format
116
+ #
117
+ # We have to make sure that the format will be proper, as otherwise
118
+ # further calculations may fail/be incorrect.
119
+ # ========================================================================= #
120
+ def set_format(i = nil)
121
+ i = '02:28:07.97' if i.nil? # Default.
122
+ i = i.to_s.dup
123
+ if i.end_with? 's'
124
+ i.chop!
125
+ end
126
+ i.tr!('m',':') if i.include? 'm'
127
+ i.tr!('h',':') if i.include? 'h'
128
+ if i.count(':') == 2 and i =~ /^\d:/
129
+ i.prepend('0') # Correct input such as '1:32:48.2' here.
130
+ end
131
+ @format = i # @format is now something like '02:28:07.97'.
132
+ end
133
+
134
+ # ========================================================================= #
135
+ # === run
136
+ # ========================================================================= #
137
+ def run
138
+ display_result # We only display it for now.
139
+ end
140
+
141
+ # ========================================================================= #
142
+ # === HoursToSeconds[]
143
+ #
144
+ # The following asks this question:
145
+ # "How many seconds does a 24 hours day have?"
146
+ #
147
+ # Usage example:
148
+ # x = HoursToSeconds[24, :be_quiet]
149
+ # ========================================================================= #
150
+ def self.[](i, optional_be_quiet = false)
151
+ _ = self.new(i, :dont_run_yet)
152
+ case optional_be_quiet
153
+ when :be_quiet, :be_silent
154
+ optional_be_quiet = true
155
+ end
156
+ _.be_silent if optional_be_quiet
157
+ _.run
158
+ return _.n_seconds
159
+ end
160
+
161
+ end
162
+
163
+ if __FILE__ == $PROGRAM_NAME
164
+ _ = HoursToSeconds.new(ARGV.first, true)
165
+ end # hours 02:28:07.97
@@ -0,0 +1,5 @@
1
+ class HoursToSeconds
2
+
3
+ VERSION = '1.0.12'
4
+
5
+ end
@@ -0,0 +1,26 @@
1
+ #!/System/Index/bin/ruby -w
2
+ # Encoding: ASCII-8BIT
3
+ # =========================================================================== #
4
+ require 'colours/autoinclude'
5
+ require 'hours_to_seconds'
6
+
7
+ input = '01:52:02.09'
8
+ e 'Input format is: '+sfancy(input)
9
+ hours_to_seconds = HoursToSeconds.new(input, :dont_run_yet)
10
+ e 'These are n seconds: '+sfancy(hours_to_seconds.n_seconds)
11
+
12
+ input = '00:15:00.00'
13
+ e 'Input format is: '+sfancy(input)
14
+ hours_to_seconds = HoursToSeconds.new(input, :dont_run_yet)
15
+ e 'These are n seconds: '+sfancy(hours_to_seconds.n_seconds)
16
+
17
+ input = '1h10m30s'
18
+ e 'Input format is: '+sfancy(input)
19
+ hours_to_seconds = HoursToSeconds.new(input, :dont_run_yet)
20
+ e 'These are n seconds: '+sfancy(hours_to_seconds.n_seconds)
21
+
22
+ # Testing '1:32:48.2' as input.
23
+ input = '1:32:48.2'
24
+ e 'Input format is: '+sfancy(input)
25
+ hours_to_seconds = HoursToSeconds.new(input, :dont_run_yet)
26
+ e 'These are n seconds: '+sfancy(hours_to_seconds.n_seconds)
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hours_to_seconds
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.12
5
+ platform: ruby
6
+ authors:
7
+ - Robert A. Heiler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colours
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: " \n This library is called hours_to_seconds.\n \n"
28
+ email: shevegen@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - USAGE.md
34
+ - hours_to_seconds.gemspec
35
+ - lib/hours_to_seconds.rb
36
+ - lib/hours_to_seconds/hours_to_seconds.rb
37
+ - lib/hours_to_seconds/version/version.rb
38
+ - test/testing_hours_to_seconds.rb
39
+ homepage: http://rubygems.org/gems/hours_to_seconds
40
+ licenses:
41
+ - GPL-2.0
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: 2.6.3
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 3.0.3
57
+ requirements: []
58
+ rubygems_version: 3.0.3
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: 'If you have specific suggestions to make this gem more useful for others,
62
+ please drop me an email at: shevegen@gmail.com Thank you.'
63
+ test_files: []