counter_container 0.0.2

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/counter_container.rb +64 -0
  3. metadata +46 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4e8da16107e69aea7c94d2cb23c0e7b54361e85af8b980ff270837d82291c3bb
4
+ data.tar.gz: 024e38f8c86e2e8743f781ff5efc5a647ececc4608fc6a2fd1579dd606bb7281
5
+ SHA512:
6
+ metadata.gz: c8a071ff4588f9adfb5963fcb1ad7cf61447ca9727d5a9a7baf5e2d56140a5e930cf315b38ae24634268332a3f0a532f8827cfa3bd75349b4aef1d16938651bd
7
+ data.tar.gz: 6bcf7fca6e04883efa7c4517f67d8250f871924d0ad2d39b07f9a08ecaa947a8bff234a41be8918a898c1bca89ceaf65505c6865adbf7e88b314ccbbe78b4be1
@@ -0,0 +1,64 @@
1
+ # Provides counting functionality for @counter. Affords
2
+ # incrementation, decrementation and resetting the count
3
+ # via convenient methods.
4
+ #
5
+ # For this module to work, @counter and @start_val are
6
+ # assumed to be of type Integer.
7
+ module CounterContainer
8
+ COUNTING_INSTANCE_OBJECT_IS_NIL = 'The counting instance attribute @counter was nil.'
9
+ COUNTING_INSTANCE_OBJECT_IS_NON_INTEGER = 'The counting instance attribute @counter is not an Integer even though it should be.'
10
+
11
+ START_VAL_INSTANCE_OBJECT_IS_NIL = 'The starting value attribute @start_val was nil.'
12
+ START_VAL_INSTANCE_OBJECT_IS_NON_INTEGER = 'The starting value attribute @start_val is not an Integer even though it should be.'
13
+
14
+ # sets @start_val, the default value of the counter
15
+ attr_writer :start_val
16
+
17
+ # sets @counter, the object holding the value of
18
+ # the current count
19
+ attr_writer :counter
20
+
21
+ # Increments @counter by Integer value of 1
22
+ def increment!
23
+ raise COUNTING_INSTANCE_OBJECT_IS_NIL if @counter.nil?
24
+ raise COUNTING_INSTANCE_OBJECT_IS_NON_INTEGER if @counter.class != Integer
25
+
26
+ @counter += 1
27
+ end
28
+
29
+ # Synonymous method for CounterContainer#increment!
30
+ def inc!
31
+ increment!
32
+ end
33
+
34
+ # Decrements @counter by Integer value of 1
35
+ def decrement!
36
+ @counter -= 1
37
+ end
38
+
39
+ # Synonymous method for CounterContainer#increment!
40
+ def dec!
41
+ raise COUNTING_INSTANCE_OBJECT_IS_NIL if @counter.nil?
42
+ raise COUNTING_INSTANCE_OBJECT_IS_NON_INTEGER if @counter.class != Integer
43
+
44
+ decrement!
45
+ end
46
+
47
+ # Gets the current count.
48
+ # @return [Integer] a duplicate of @counter
49
+ def count
50
+ raise COUNTING_INSTANCE_OBJECT_IS_NIL if @counter.nil?
51
+ raise COUNTING_INSTANCE_OBJECT_IS_NON_INTEGER if @counter.class != Integer
52
+ @counter
53
+ end
54
+
55
+ # Resets the value of @counter to @basis
56
+ def reset!
57
+ raise COUNTING_INSTANCE_OBJECT_IS_NIL if @counter.nil?
58
+ raise COUNTING_INSTANCE_OBJECT_IS_NON_INTEGER if @counter.class != Integer
59
+ raise START_VAL_INSTANCE_OBJECT_IS_NIL if @start_val.nil?
60
+ raise START_VAL_INSTANCE_OBJECT_IS_NON_INTEGER if @start_val.class != Integer
61
+
62
+ @counter = @start_val.dup
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: counter_container
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Jacob Barnard
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-09-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Provides access to the module CounterContainer. Including CounterContainer
14
+ allows classes with an Integer attribute (@counter) to gain incrementing, decrementing,
15
+ and other functionality.
16
+ email: jmbarnardg1@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/counter_container.rb
22
+ homepage: https://github.com/jmbarnardgh/counter_container/tree/master
23
+ licenses:
24
+ - Apache-2.0
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubygems_version: 3.2.15
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Provides the CounterContainer module, allowing classes to manipulate a counting
45
+ object.
46
+ test_files: []