Class: CarCodes::Code
Constant Summary
Constants included
from Definitions
Definitions::CATEGORIES, Definitions::FUEL, Definitions::TRANSMISSIONS, Definitions::TYPES
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(word = "") ⇒ Code
Returns a new instance of Code.
7
8
9
10
11
12
13
|
# File 'lib/car_codes/code.rb', line 7
def initialize(word = "")
@word = word.upcase
@category = CATEGORIES[word[0]]
@type = TYPES[word[1]]
@transmission = TRANSMISSIONS[word[2]]
@fuel = FUEL[word[3]]
end
|
Instance Attribute Details
#word ⇒ Object
Returns the value of attribute word.
5
6
7
|
# File 'lib/car_codes/code.rb', line 5
def word
@word
end
|
Instance Method Details
#category ⇒ Object
20
21
22
23
|
# File 'lib/car_codes/code.rb', line 20
def category
ensure_validation
@category
end
|
#fuel ⇒ Object
35
36
37
38
|
# File 'lib/car_codes/code.rb', line 35
def fuel
ensure_validation
@fuel
end
|
#to_human ⇒ Object
15
16
17
18
|
# File 'lib/car_codes/code.rb', line 15
def to_human
ensure_validation
"#{category} - #{type} - #{transmission} - #{fuel}"
end
|
#transmission ⇒ Object
30
31
32
33
|
# File 'lib/car_codes/code.rb', line 30
def transmission
ensure_validation
@transmission
end
|
#type ⇒ Object
25
26
27
28
|
# File 'lib/car_codes/code.rb', line 25
def type
ensure_validation
@type
end
|
#valid? ⇒ Boolean
40
41
42
43
44
45
46
|
# File 'lib/car_codes/code.rb', line 40
def valid?
!!(word.length == 4 &&
@category &&
@type &&
@transmission &&
@fuel)
end
|