sdn_test_simple_car 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53b49bdbac04dae0f2ccf0d0ebe6ea82f947a333e36082eece3d215e9ce2ab7c
4
- data.tar.gz: 2f347ba4ffc702edfa2c9e0955c45660710eeb1788ddd6b2648acf2676dc0027
3
+ metadata.gz: 1d4ce8b6353f79496e98909d6accfe410702b20057122d4c5a2d5cd63485b70d
4
+ data.tar.gz: 57d44e640b383288fec007a76bd2f578a715bbf5e7d2362fa751784e10f69e01
5
5
  SHA512:
6
- metadata.gz: 7e745d8cf6af3aa7635e6de2ebde4c2fbbbc36b300a659e681721b3bcf116c65c0f216197057021c1364152239e791ee66b2ca1f61cfca4a09629beb156306d2
7
- data.tar.gz: 7043cd44f5657acf8c369411164788ebb9cf50f486eacd181ffa6444740ab7fd5169412fac2fdc5b0c67564c2d914e2471845d1099f83f14f688c01ff61cf28c
6
+ metadata.gz: cab595f69ead35116358d71609cca177704eb8bf971a2f3e61c2eea99512780f131acfc3e91c60bca108fc0eabbae209b292e750ff7a22f58000c9553ee45e34
7
+ data.tar.gz: d0727cb4f5ac213f734c065b6314fa876843a12e63d46f15a502ba0d55c14a422af5899e0b8bacb4d66d34ed37fcc25ed2ff6c117ad2fe741dac341d39168e79
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml CHANGED
@@ -1,8 +1,8 @@
1
- AllCops:
2
- TargetRubyVersion: 3.1
3
-
4
- Style/StringLiterals:
5
- EnforcedStyle: double_quotes
6
-
7
- Style/StringLiteralsInInterpolation:
8
- EnforcedStyle: double_quotes
1
+ AllCops:
2
+ TargetRubyVersion: 3.1
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
data/LICENSE.txt CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2026 Graftcode
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.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Graftcode
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.
data/README.md CHANGED
@@ -1,74 +1,74 @@
1
- # SimpleCar
2
-
3
- A minimal Ruby class that represents a car and its running state.
4
-
5
- ## What it provides
6
-
7
- - Auto-generated UUID `id` (or custom `id`)
8
- - Car metadata: `make`, `model`, `year`
9
- - Engine state control: `start`, `stop`, `is_running`
10
- - String representation via `to_s`
11
-
12
- ## Requirements
13
-
14
- - Ruby 3.1+
15
-
16
- ## Import
17
-
18
- Use one of the following approaches:
19
-
20
- ```ruby
21
- require "simple_car"
22
- ```
23
-
24
- or, when loading directly from the repository:
25
-
26
- ```ruby
27
- require_relative "lib/simple_car"
28
- ```
29
-
30
- ## Quick Start
31
-
32
- ```ruby
33
- require "simple_car"
34
-
35
- car = SimpleCar.new("Toyota", "Corolla", 2020)
36
-
37
- puts car.id # generated UUID
38
- puts car.make # "Toyota"
39
- puts car.model # "Corolla"
40
- puts car.year # 2020
41
- puts car.wheels # 4
42
- puts car.is_running # false
43
-
44
- car.start
45
- puts car.is_running # true
46
-
47
- car.stop
48
- puts car.is_running # false
49
-
50
- puts car.to_s
51
- # => "<id> 2020 Toyota Corolla (SimpleCar) Not Running"
52
- ```
53
-
54
- ## Custom ID
55
-
56
- ```ruby
57
- car = SimpleCar.new("Ford", "Mustang", 1968, "car-001")
58
- puts car.id # "car-001"
59
- ```
60
-
61
- If `id` is `nil` or empty, `SimpleCar` generates a UUID automatically.
62
-
63
- ## API Reference
64
-
65
- - `SimpleCar.new(make, model, year, id = nil)`
66
- - `id` -> `String`
67
- - `make` -> `String`
68
- - `model` -> `String`
69
- - `year` -> `Integer` (or any value passed in)
70
- - `wheels` -> `4`
71
- - `is_running` -> `true` / `false`
72
- - `start` -> sets running state to `true`
73
- - `stop` -> sets running state to `false`
1
+ # SimpleCar
2
+
3
+ A minimal Ruby class that represents a car and its running state.
4
+
5
+ ## What it provides
6
+
7
+ - Auto-generated UUID `id` (or custom `id`)
8
+ - Car metadata: `make`, `model`, `year`
9
+ - Engine state control: `start`, `stop`, `is_running`
10
+ - String representation via `to_s`
11
+
12
+ ## Requirements
13
+
14
+ - Ruby 3.1+
15
+
16
+ ## Import
17
+
18
+ Use one of the following approaches:
19
+
20
+ ```ruby
21
+ require "simple_car"
22
+ ```
23
+
24
+ or, when loading directly from the repository:
25
+
26
+ ```ruby
27
+ require_relative "lib/simple_car"
28
+ ```
29
+
30
+ ## Quick Start
31
+
32
+ ```ruby
33
+ require "simple_car"
34
+
35
+ car = SimpleCar.new("Toyota", "Corolla", 2020)
36
+
37
+ puts car.id # generated UUID
38
+ puts car.make # "Toyota"
39
+ puts car.model # "Corolla"
40
+ puts car.year # 2020
41
+ puts car.wheels # 4
42
+ puts car.is_running # false
43
+
44
+ car.start
45
+ puts car.is_running # true
46
+
47
+ car.stop
48
+ puts car.is_running # false
49
+
50
+ puts car.to_s
51
+ # => "<id> 2020 Toyota Corolla (SimpleCar) Not Running"
52
+ ```
53
+
54
+ ## Custom ID
55
+
56
+ ```ruby
57
+ car = SimpleCar.new("Ford", "Mustang", 1968, "car-001")
58
+ puts car.id # "car-001"
59
+ ```
60
+
61
+ If `id` is `nil` or empty, `SimpleCar` generates a UUID automatically.
62
+
63
+ ## API Reference
64
+
65
+ - `SimpleCar.new(make, model, year, id = nil)`
66
+ - `id` -> `String`
67
+ - `make` -> `String`
68
+ - `model` -> `String`
69
+ - `year` -> `Integer` (or any value passed in)
70
+ - `wheels` -> `4`
71
+ - `is_running` -> `true` / `false`
72
+ - `start` -> sets running state to `true`
73
+ - `stop` -> sets running state to `false`
74
74
  - `to_s` -> `"<id> <year> <make> <model> (SimpleCar) <Running|Not Running>"`
data/Rakefile CHANGED
@@ -1,12 +1,12 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- require "rubocop/rake_task"
9
-
10
- RuboCop::RakeTask.new
11
-
12
- task default: %i[spec rubocop]
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
- module GrftTestSimpleCar
4
- VERSION = "0.1.0"
5
- end
1
+ # frozen_string_literal: true
2
+
3
+ module GrftTestSimpleCar
4
+ VERSION = "0.2.0"
5
+ end
data/lib/simple_car.rb CHANGED
@@ -1,35 +1,107 @@
1
- # frozen_string_literal: true
2
-
3
- require "securerandom"
4
-
5
- class SimpleCar
6
- attr_reader :id, :make, :model, :year
7
-
8
- def initialize(make, model, year, id = nil)
9
- @id = id.nil? || id.strip.empty? ? SecureRandom.uuid : id
10
- @make = make
11
- @model = model
12
- @year = year
13
- @is_running = false
14
- end
15
-
16
- def wheels
17
- 4
18
- end
19
-
20
- def is_running
21
- @is_running
22
- end
23
-
24
- def start
25
- @is_running = true
26
- end
27
-
28
- def stop
29
- @is_running = false
30
- end
31
-
32
- def to_s
33
- "#{@id} #{@year} #{@make} #{@model} (SimpleCar) #{@is_running ? "Running" : "Not Running"}"
34
- end
35
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "securerandom"
4
+ require_relative "vehicle"
5
+
6
+ # Represents a simplified car that uses a string identifier instead of a GUID.
7
+ # Includes the Vehicle module and covers:
8
+ # primitive fields, static members, constructors, primitive-array I/O,
9
+ # and methods that accept / return complex types from the same library.
10
+ class SimpleCar
11
+ include Vehicle
12
+
13
+ # ── static members ──────────────────────────────────────────────
14
+
15
+ DEFAULT_WHEELS = 4
16
+
17
+ @total_cars_created = 0
18
+
19
+ class << self
20
+ attr_reader :total_cars_created
21
+
22
+ def create_default
23
+ new("DefaultMake", "DefaultModel", 2024)
24
+ end
25
+
26
+ def get_default_makes
27
+ %w[Toyota Tesla Ford Honda Chevrolet]
28
+ end
29
+ end
30
+
31
+ # ── instance accessors ─────────────────────────────────────────
32
+
33
+ attr_reader :id, :make, :model, :year
34
+
35
+ def initialize(make, model, year, id = nil)
36
+ @id = id.nil? || id.strip.empty? ? SecureRandom.uuid : id
37
+ @make = make
38
+ @model = model
39
+ @year = year
40
+ @is_running = false
41
+ @mileage_history = []
42
+ @tags = []
43
+ self.class.instance_variable_set(:@total_cars_created, self.class.total_cars_created + 1)
44
+ end
45
+
46
+ # ── properties (Vehicle) ───────────────────────────────────────
47
+
48
+ def wheels
49
+ DEFAULT_WHEELS
50
+ end
51
+
52
+ def is_running
53
+ @is_running
54
+ end
55
+
56
+ # ── engine control (Vehicle) ───────────────────────────────────
57
+
58
+ def start
59
+ @is_running = true
60
+ end
61
+
62
+ def stop
63
+ @is_running = false
64
+ end
65
+
66
+ # ── primitive-array methods ────────────────────────────────────
67
+
68
+ def add_mileage_entry(miles)
69
+ @mileage_history << miles
70
+ end
71
+
72
+ def get_mileage_history
73
+ @mileage_history.dup
74
+ end
75
+
76
+ def set_tags(tags)
77
+ @tags = tags ? tags.dup : []
78
+ end
79
+
80
+ def get_tags
81
+ @tags.dup
82
+ end
83
+
84
+ # ── complex-type methods ───────────────────────────────────────
85
+
86
+ def duplicate
87
+ copy = SimpleCar.new(@make, @model, @year, @id)
88
+ copy.instance_variable_set(:@is_running, @is_running)
89
+ copy.instance_variable_set(:@mileage_history, @mileage_history.dup)
90
+ copy.instance_variable_set(:@tags, @tags.dup)
91
+ copy
92
+ end
93
+
94
+ def with_year(new_year)
95
+ copy = SimpleCar.new(@make, @model, new_year, @id)
96
+ copy.instance_variable_set(:@is_running, @is_running)
97
+ copy.instance_variable_set(:@mileage_history, @mileage_history.dup)
98
+ copy.instance_variable_set(:@tags, @tags.dup)
99
+ copy
100
+ end
101
+
102
+ # ── object overrides ───────────────────────────────────────────
103
+
104
+ def to_s
105
+ "#{@id} #{@year} #{@make} #{@model} (SimpleCar) #{@is_running ? "Running" : "Not Running"}"
106
+ end
107
+ end
data/lib/vehicle.rb ADDED
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Contract (mixin) for any vehicle with basic identity, state, and engine control.
4
+ #
5
+ # Including classes must provide: id, make, model, year, wheels, is_running, start, stop.
6
+ module Vehicle
7
+ def id
8
+ raise NotImplementedError
9
+ end
10
+
11
+ def make
12
+ raise NotImplementedError
13
+ end
14
+
15
+ def model
16
+ raise NotImplementedError
17
+ end
18
+
19
+ def year
20
+ raise NotImplementedError
21
+ end
22
+
23
+ def wheels
24
+ raise NotImplementedError
25
+ end
26
+
27
+ def is_running
28
+ raise NotImplementedError
29
+ end
30
+
31
+ def start
32
+ raise NotImplementedError
33
+ end
34
+
35
+ def stop
36
+ raise NotImplementedError
37
+ end
38
+ end
Binary file
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sdn_test_simple_car
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GraftCode
8
+ autorequire:
8
9
  bindir: exe
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2026-04-08 00:00:00.000000000 Z
11
12
  dependencies: []
12
13
  description: Provides a lightweight SimpleCar class with make/model/year data, auto-generated
13
14
  IDs, engine start/stop state, and a readable string representation.
@@ -24,11 +25,14 @@ files:
24
25
  - Rakefile
25
26
  - lib/grft_test_simple_car/version.rb
26
27
  - lib/simple_car.rb
28
+ - lib/vehicle.rb
29
+ - sdn_test_simple_car-0.1.0.gem
27
30
  homepage: https://graftcode.com
28
31
  licenses:
29
32
  - MIT
30
33
  metadata:
31
34
  homepage_uri: https://graftcode.com
35
+ post_install_message:
32
36
  rdoc_options: []
33
37
  require_paths:
34
38
  - lib
@@ -43,7 +47,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
43
47
  - !ruby/object:Gem::Version
44
48
  version: '0'
45
49
  requirements: []
46
- rubygems_version: 3.6.9
50
+ rubygems_version: 3.5.22
51
+ signing_key:
47
52
  specification_version: 4
48
53
  summary: A minimal SimpleCar model with runtime state management.
49
54
  test_files: []