11class Auto
2- attr_reader :id_owner , :model , :color , :surname_owner
2+ attr_reader :id_owner , :model , :color , :surname_owner , :mark
33 attr_accessor :id
44
55 define_singleton_method :check_word do |word |
@@ -14,25 +14,26 @@ class Auto
1414 /^[\- A-z0-9]+$/ . match ( word )
1515 end
1616
17- def initialize ( id :, id_owner :, surname_owner :, model :, color :)
18- set_baseInfo ( id_owner :id_owner , surname_owner :surname_owner , model :model , color :color )
17+ def initialize ( id :, id_owner :, surname_owner :, model :, color :, mark : )
18+ set_baseInfo ( id_owner :id_owner , surname_owner :surname_owner , model :model , color :color , mark : mark )
1919 self . id = id
2020 end
2121
2222 def self . initialization ( information )
23- raise "Not enough data or exists unnecessary data!(split [,])" if ( information . count ( "," ) > 5 || information . count ( "," ) == 0 )
23+ raise "Not enough data or exists unnecessary data!(split [,])" if ( information . count ( "," ) > 6 || information . count ( "," ) == 0 )
2424 hash_data = Auto . string_to_hash ( information . delete ( ' ' ) . split ( "," ) )
25- Auto . new ( id :hash_data [ "id" ] , id_owner :Integer ( hash_data [ "id_owner" ] ) , surname_owner :hash_data [ "surname_owner" ] , model :hash_data [ "model" ] , color :hash_data [ "color" ] )
25+ Auto . new ( id :hash_data [ "id" ] , id_owner :Integer ( hash_data [ "id_owner" ] ) , surname_owner :hash_data [ "surname_owner" ] , model :hash_data [ "model" ] , color :hash_data [ "color" ] , mark : hash_data [ "mark" ] )
2626 end
2727
2828 def to_s ( )
2929 "#{ self . model } #{ self . color } "
3030 end
31- def set_baseInfo ( id_owner :nil , surname_owner :nil , model :nil , color :nil )
32- valid_baseField_onCorrect ( id_owner :id_owner , surname_owner :surname_owner , model :model , color :color )
31+ def set_baseInfo ( id_owner :nil , surname_owner :nil , model :nil , color :nil , mark : nil )
32+ valid_baseField_onCorrect ( id_owner :id_owner , surname_owner :surname_owner , model :model , color :color , mark : mark )
3333 self . id_owner = id_owner if ( id_owner !=nil )
3434 self . surname_owner = surname_owner if ( surname_owner != nil )
3535 self . model = model if ( model !=nil )
36+ self . mark = mark if ( mark !=nil )
3637 self . color = color if ( color !=nil )
3738 end
3839
@@ -42,19 +43,20 @@ def get_info()
4243
4344
4445 private
45- attr_writer :id_owner , :model , :color , :surname_owner
46+ attr_writer :id_owner , :model , :color , :surname_owner , :mark
4647
4748 def self . string_to_hash ( data )
4849 hash_data = Hash . new
4950 hash_data [ "id" ] = data [ 0 ]
5051 hash_data [ "id_owner" ] = data [ 1 ]
5152 hash_data [ "surname_owner" ] = data [ 2 ]
52- hash_data [ "model" ] = data [ 3 ]
53- hash_data [ "color" ] = data [ 4 ]
53+ hash_data [ "model" ] = data [ 3 ]
54+ hash_data [ "mark" ] = data [ 4 ]
55+ hash_data [ "color" ] = data [ 5 ]
5456 hash_data
5557 end
5658
57- def valid_baseField_onCorrect ( id_owner :, model :, color :, surname_owner :)
59+ def valid_baseField_onCorrect ( id_owner :, model :, color :, surname_owner :, mark : )
5860 if ( color !=nil ) then
5961 raise "Not valid color [A-Z][a-z]+ #{ color } " if ( Auto . check_word ( color ) == nil || color . length > 50 )
6062 end
@@ -67,6 +69,9 @@ def valid_baseField_onCorrect(id_owner:,model:,color:,surname_owner:)
6769 if ( model !=nil ) then
6870 raise "Not valid model #{ model } " if ( Auto . check_no_special_symbol ( model ) == nil )
6971 end
72+ if ( mark !=nil ) then
73+ raise "Not valid mark #{ mark } " if ( Auto . check_no_special_symbol ( mark ) == nil )
74+ end
7075 end
7176
7277
0 commit comments