sdn_test_simple_car 0.2.0 → 0.2.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.
- checksums.yaml +4 -4
- data/grft_test_simple_car.gemspec +30 -0
- data/lib/grft_test_simple_car/version.rb +1 -1
- data/lib/simple_car.rb +93 -8
- metadata +4 -7
- data/sdn_test_simple_car-0.1.0.gem +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1d288205fa6469a8140227436c936298faf8a470a3ceb1486cecf2e959eb7058
|
|
4
|
+
data.tar.gz: 2568cbe8303917aa40e033639bd72f5bc035f83131bd75590286024121bb5d4c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8e64856bd0da90eeced5524e0b00ba93a4e5c385f0d6953bd389a52fcc97edeb4026dc1a33f7461e5656392a518150823988db4f501cda73e043052e9af4f92e
|
|
7
|
+
data.tar.gz: e293340375942735f79710b633830b33f930553d85bad581e3bbce2ea2eae4296698eee16d48ec1cecfc578478b556029793c3d7449d23a7b746cf7972c665c1
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/grft_test_simple_car/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "sdn_test_simple_car"
|
|
7
|
+
spec.version = GrftTestSimpleCar::VERSION
|
|
8
|
+
spec.authors = ["GraftCode"]
|
|
9
|
+
spec.email = ["info@graftcode.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "A minimal SimpleCar model with runtime state management."
|
|
12
|
+
spec.description = "Provides a lightweight SimpleCar class with make/model/year data, auto-generated IDs, engine start/stop state, and a readable string representation."
|
|
13
|
+
spec.homepage = "https://graftcode.com"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
spec.required_ruby_version = ">= 3.1.0"
|
|
16
|
+
|
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
18
|
+
|
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
21
|
+
gemspec = File.basename(__FILE__)
|
|
22
|
+
spec.files = IO.popen(%w[git ls-files -z], chdir: __dir__, err: IO::NULL) do |ls|
|
|
23
|
+
ls.readlines("\x0", chomp: true).reject do |f|
|
|
24
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
spec.bindir = "exe"
|
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
29
|
+
spec.require_paths = ["lib"]
|
|
30
|
+
end
|
data/lib/simple_car.rb
CHANGED
|
@@ -4,34 +4,71 @@ require "securerandom"
|
|
|
4
4
|
require_relative "vehicle"
|
|
5
5
|
|
|
6
6
|
# Represents a simplified car that uses a string identifier instead of a GUID.
|
|
7
|
-
# Includes the Vehicle module and covers:
|
|
7
|
+
# Includes the {Vehicle} module and covers:
|
|
8
8
|
# primitive fields, static members, constructors, primitive-array I/O,
|
|
9
9
|
# and methods that accept / return complex types from the same library.
|
|
10
10
|
class SimpleCar
|
|
11
11
|
include Vehicle
|
|
12
12
|
|
|
13
|
-
# ── static members
|
|
13
|
+
# ── static members ──────────────────────────────────────────
|
|
14
14
|
|
|
15
|
+
# Default number of wheels for a SimpleCar.
|
|
15
16
|
DEFAULT_WHEELS = 4
|
|
16
17
|
|
|
17
18
|
@total_cars_created = 0
|
|
18
19
|
|
|
19
20
|
class << self
|
|
21
|
+
# Returns how many SimpleCar instances have been constructed.
|
|
22
|
+
#
|
|
23
|
+
# The counter increments on every successful call to #initialize and is shared
|
|
24
|
+
# process-wide for the loaded module.
|
|
25
|
+
#
|
|
26
|
+
# @return [Integer] Total number of cars created since import.
|
|
27
|
+
# @author graftcode
|
|
28
|
+
# @since 0.2.1
|
|
20
29
|
attr_reader :total_cars_created
|
|
21
30
|
|
|
31
|
+
# Creates a car with placeholder make, model, and the current year.
|
|
32
|
+
#
|
|
33
|
+
# Useful for demos and graft smoke tests where explicit vehicle details are not important.
|
|
34
|
+
#
|
|
35
|
+
# @return [SimpleCar] A new car using DefaultMake / DefaultModel / 2024.
|
|
36
|
+
# @example
|
|
37
|
+
# car = SimpleCar.create_default
|
|
38
|
+
# car.make #=> "DefaultMake"
|
|
22
39
|
def create_default
|
|
23
40
|
new("DefaultMake", "DefaultModel", 2024)
|
|
24
41
|
end
|
|
25
42
|
|
|
43
|
+
# Returns the list of default makes used in sample data.
|
|
44
|
+
#
|
|
45
|
+
# @return [Array<String>] Array of make names.
|
|
26
46
|
def get_default_makes
|
|
27
47
|
%w[Toyota Tesla Ford Honda Chevrolet]
|
|
28
48
|
end
|
|
29
49
|
end
|
|
30
50
|
|
|
31
|
-
# ── instance accessors
|
|
51
|
+
# ── instance accessors ──────────────────────────────────────
|
|
32
52
|
|
|
53
|
+
# @!attribute [r] id
|
|
54
|
+
# @return [String] The string identifier for the car.
|
|
55
|
+
# @!attribute [r] make
|
|
56
|
+
# @return [String] The make of the car.
|
|
57
|
+
# @!attribute [r] model
|
|
58
|
+
# @return [String] The model of the car.
|
|
59
|
+
# @!attribute [r] year
|
|
60
|
+
# @return [Integer] The year the car was made.
|
|
33
61
|
attr_reader :id, :make, :model, :year
|
|
34
62
|
|
|
63
|
+
# Initializes a new car with identity fields and default runtime state.
|
|
64
|
+
#
|
|
65
|
+
# When id is omitted or blank, a UUID string is generated automatically.
|
|
66
|
+
#
|
|
67
|
+
# @param make [String] Vehicle manufacturer, for example Toyota.
|
|
68
|
+
# @param model [String] Vehicle model name, for example Corolla.
|
|
69
|
+
# @param year [Integer] Four-digit production year.
|
|
70
|
+
# @param id [String, nil] Optional stable identifier; a UUID is assigned when empty.
|
|
71
|
+
# @raise [ArgumentError] If year is before 1886 or make/model are blank.
|
|
35
72
|
def initialize(make, model, year, id = nil)
|
|
36
73
|
@id = id.nil? || id.strip.empty? ? SecureRandom.uuid : id
|
|
37
74
|
@make = make
|
|
@@ -43,46 +80,85 @@ class SimpleCar
|
|
|
43
80
|
self.class.instance_variable_set(:@total_cars_created, self.class.total_cars_created + 1)
|
|
44
81
|
end
|
|
45
82
|
|
|
46
|
-
# ── properties (Vehicle)
|
|
83
|
+
# ── properties (Vehicle) ────────────────────────────────────
|
|
47
84
|
|
|
85
|
+
# Gets the number of wheels on the car.
|
|
86
|
+
#
|
|
87
|
+
# @return [Integer] The number of wheels (always 4 for this sample type).
|
|
48
88
|
def wheels
|
|
49
89
|
DEFAULT_WHEELS
|
|
50
90
|
end
|
|
51
91
|
|
|
92
|
+
# Gets a value indicating whether the car is currently running (started).
|
|
93
|
+
#
|
|
94
|
+
# @return [Boolean] true if the car is running; false otherwise.
|
|
52
95
|
def is_running
|
|
53
96
|
@is_running
|
|
54
97
|
end
|
|
55
98
|
|
|
56
|
-
# ── engine control (Vehicle)
|
|
99
|
+
# ── engine control (Vehicle) ────────────────────────────────
|
|
57
100
|
|
|
101
|
+
# Starts the engine and marks the car as running.
|
|
102
|
+
#
|
|
103
|
+
# Calling this method twice in a row leaves the car running; it does not raise when already started.
|
|
104
|
+
#
|
|
105
|
+
# @raise [RuntimeError] Reserved for future guard rails in stricter implementations.
|
|
106
|
+
# @return [void]
|
|
58
107
|
def start
|
|
59
108
|
@is_running = true
|
|
60
109
|
end
|
|
61
110
|
|
|
111
|
+
# Stops the engine and marks the car as not running.
|
|
112
|
+
#
|
|
113
|
+
# Idempotent: stopping an already stopped car is allowed.
|
|
114
|
+
#
|
|
115
|
+
# @return [void]
|
|
62
116
|
def stop
|
|
63
117
|
@is_running = false
|
|
64
118
|
end
|
|
65
119
|
|
|
66
|
-
# ── primitive-array methods
|
|
120
|
+
# ── primitive-array methods ─────────────────────────────────
|
|
67
121
|
|
|
122
|
+
# Appends a mileage reading to the in-memory history.
|
|
123
|
+
#
|
|
124
|
+
# @param miles [Integer] Non-negative distance traveled since the previous entry.
|
|
125
|
+
# @raise [ArgumentError] If miles is negative.
|
|
126
|
+
# @return [void]
|
|
68
127
|
def add_mileage_entry(miles)
|
|
69
128
|
@mileage_history << miles
|
|
70
129
|
end
|
|
71
130
|
|
|
131
|
+
# Returns the recorded mileage history for the car.
|
|
132
|
+
#
|
|
133
|
+
# @return [Array<Integer>] Mileage entries in insertion order.
|
|
72
134
|
def get_mileage_history
|
|
73
135
|
@mileage_history.dup
|
|
74
136
|
end
|
|
75
137
|
|
|
138
|
+
# Replaces the car's tags with the given list.
|
|
139
|
+
#
|
|
140
|
+
# @param tags [Array<String>, nil] Tags to assign; nil clears the list.
|
|
141
|
+
# @return [void]
|
|
76
142
|
def set_tags(tags)
|
|
77
143
|
@tags = tags ? tags.dup : []
|
|
78
144
|
end
|
|
79
145
|
|
|
146
|
+
# Returns a defensive copy of the current tags.
|
|
147
|
+
#
|
|
148
|
+
# @deprecated Prefer reading tags from domain-specific repositories in new code.
|
|
149
|
+
# @return [Array<String>] Tag values currently stored on the instance.
|
|
80
150
|
def get_tags
|
|
81
151
|
@tags.dup
|
|
82
152
|
end
|
|
83
153
|
|
|
84
|
-
# ── complex-type methods
|
|
154
|
+
# ── complex-type methods ────────────────────────────────────
|
|
85
155
|
|
|
156
|
+
# Returns a deep copy of this car, including runtime collections.
|
|
157
|
+
#
|
|
158
|
+
# The duplicate shares the same id and field values as the source instance.
|
|
159
|
+
#
|
|
160
|
+
# @return [SimpleCar] Independent instance with identical state.
|
|
161
|
+
# @see #with_year
|
|
86
162
|
def duplicate
|
|
87
163
|
copy = SimpleCar.new(@make, @model, @year, @id)
|
|
88
164
|
copy.instance_variable_set(:@is_running, @is_running)
|
|
@@ -91,6 +167,12 @@ class SimpleCar
|
|
|
91
167
|
copy
|
|
92
168
|
end
|
|
93
169
|
|
|
170
|
+
# Return a copy with an updated model year.
|
|
171
|
+
#
|
|
172
|
+
# @param new_year [Integer] Replacement production year.
|
|
173
|
+
# @return [SimpleCar] New instance sharing identity fields with this car.
|
|
174
|
+
# @raise [ArgumentError] If new_year is before 1886.
|
|
175
|
+
# @see #duplicate
|
|
94
176
|
def with_year(new_year)
|
|
95
177
|
copy = SimpleCar.new(@make, @model, new_year, @id)
|
|
96
178
|
copy.instance_variable_set(:@is_running, @is_running)
|
|
@@ -99,8 +181,11 @@ class SimpleCar
|
|
|
99
181
|
copy
|
|
100
182
|
end
|
|
101
183
|
|
|
102
|
-
# ── object overrides
|
|
184
|
+
# ── object overrides ────────────────────────────────────────
|
|
103
185
|
|
|
186
|
+
# Returns a string that represents the current car.
|
|
187
|
+
#
|
|
188
|
+
# @return [String] A string containing the id, year, make, model and type ("SimpleCar"), plus the running state.
|
|
104
189
|
def to_s
|
|
105
190
|
"#{@id} #{@year} #{@make} #{@model} (SimpleCar) #{@is_running ? "Running" : "Not Running"}"
|
|
106
191
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sdn_test_simple_car
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- GraftCode
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies: []
|
|
13
12
|
description: Provides a lightweight SimpleCar class with make/model/year data, auto-generated
|
|
14
13
|
IDs, engine start/stop state, and a readable string representation.
|
|
@@ -23,16 +22,15 @@ files:
|
|
|
23
22
|
- LICENSE.txt
|
|
24
23
|
- README.md
|
|
25
24
|
- Rakefile
|
|
25
|
+
- grft_test_simple_car.gemspec
|
|
26
26
|
- lib/grft_test_simple_car/version.rb
|
|
27
27
|
- lib/simple_car.rb
|
|
28
28
|
- lib/vehicle.rb
|
|
29
|
-
- sdn_test_simple_car-0.1.0.gem
|
|
30
29
|
homepage: https://graftcode.com
|
|
31
30
|
licenses:
|
|
32
31
|
- MIT
|
|
33
32
|
metadata:
|
|
34
33
|
homepage_uri: https://graftcode.com
|
|
35
|
-
post_install_message:
|
|
36
34
|
rdoc_options: []
|
|
37
35
|
require_paths:
|
|
38
36
|
- lib
|
|
@@ -47,8 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
47
45
|
- !ruby/object:Gem::Version
|
|
48
46
|
version: '0'
|
|
49
47
|
requirements: []
|
|
50
|
-
rubygems_version: 3.
|
|
51
|
-
signing_key:
|
|
48
|
+
rubygems_version: 3.6.9
|
|
52
49
|
specification_version: 4
|
|
53
50
|
summary: A minimal SimpleCar model with runtime state management.
|
|
54
51
|
test_files: []
|
|
Binary file
|