sdn_test_simple_car 0.1.0 → 0.2.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.
- 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 +73 -1
- data/lib/vehicle.rb +38 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a8dcd5c96a07178afc5ba18e84fb8231f899ecaa731719945a49d72bf95ae59d
|
|
4
|
+
data.tar.gz: 20bd7b6bd6eff1295c66fe644ef208b4c8a84e0f47eade6f874ebf1bbd72ecf4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8b288316b533e0afa20d351d49f80800d9b1e08259f21dcadde1b9ed5dca87b34303e168614ee33f5f85bdde5aac3d1077418b9d939cd0ae9615a761e392b990
|
|
7
|
+
data.tar.gz: bc61b866a39ad3d962c70177cd40c77a49870bc9d143955a1260d3d2e236d5e78dbe28b2b65244a1eaf923d0b6f2e77a3c306ea691b721681d9f9731665a2d59
|
|
@@ -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
|
@@ -1,8 +1,35 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "securerandom"
|
|
4
|
+
require_relative "vehicle"
|
|
4
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.
|
|
5
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
|
+
|
|
6
33
|
attr_reader :id, :make, :model, :year
|
|
7
34
|
|
|
8
35
|
def initialize(make, model, year, id = nil)
|
|
@@ -11,16 +38,23 @@ class SimpleCar
|
|
|
11
38
|
@model = model
|
|
12
39
|
@year = year
|
|
13
40
|
@is_running = false
|
|
41
|
+
@mileage_history = []
|
|
42
|
+
@tags = []
|
|
43
|
+
self.class.instance_variable_set(:@total_cars_created, self.class.total_cars_created + 1)
|
|
14
44
|
end
|
|
15
45
|
|
|
46
|
+
# ── properties (Vehicle) ───────────────────────────────────────
|
|
47
|
+
|
|
16
48
|
def wheels
|
|
17
|
-
|
|
49
|
+
DEFAULT_WHEELS
|
|
18
50
|
end
|
|
19
51
|
|
|
20
52
|
def is_running
|
|
21
53
|
@is_running
|
|
22
54
|
end
|
|
23
55
|
|
|
56
|
+
# ── engine control (Vehicle) ───────────────────────────────────
|
|
57
|
+
|
|
24
58
|
def start
|
|
25
59
|
@is_running = true
|
|
26
60
|
end
|
|
@@ -29,6 +63,44 @@ class SimpleCar
|
|
|
29
63
|
@is_running = false
|
|
30
64
|
end
|
|
31
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
|
+
|
|
32
104
|
def to_s
|
|
33
105
|
"#{@id} #{@year} #{@make} #{@model} (SimpleCar) #{@is_running ? "Running" : "Not Running"}"
|
|
34
106
|
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
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sdn_test_simple_car
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- GraftCode
|
|
@@ -22,8 +22,10 @@ files:
|
|
|
22
22
|
- LICENSE.txt
|
|
23
23
|
- README.md
|
|
24
24
|
- Rakefile
|
|
25
|
+
- grft_test_simple_car.gemspec
|
|
25
26
|
- lib/grft_test_simple_car/version.rb
|
|
26
27
|
- lib/simple_car.rb
|
|
28
|
+
- lib/vehicle.rb
|
|
27
29
|
homepage: https://graftcode.com
|
|
28
30
|
licenses:
|
|
29
31
|
- MIT
|