Class: AutoServiceCLI::ServiceCenter

Inherits:
Object
  • Object
show all
Defined in:
lib/auto_service_cli/service_center.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ ServiceCenter

Constructors



20
21
22
# File 'lib/auto_service_cli/service_center.rb', line 20

def initialize(name)
  @name = name
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



2
3
4
# File 'lib/auto_service_cli/service_center.rb', line 2

def address
  @address
end

#brandsObject

Returns the value of attribute brands.



2
3
4
# File 'lib/auto_service_cli/service_center.rb', line 2

def brands
  @brands
end

#descriptionObject

Returns the value of attribute description.



2
3
4
# File 'lib/auto_service_cli/service_center.rb', line 2

def description
  @description
end

#ext_urlObject

Returns the value of attribute ext_url.



2
3
4
# File 'lib/auto_service_cli/service_center.rb', line 2

def ext_url
  @ext_url
end

#int_urlObject

Returns the value of attribute int_url.



2
3
4
# File 'lib/auto_service_cli/service_center.rb', line 2

def int_url
  @int_url
end

#main_categoryObject

Returns the value of attribute main_category.



2
3
4
# File 'lib/auto_service_cli/service_center.rb', line 2

def main_category
  @main_category
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/auto_service_cli/service_center.rb', line 2

def name
  @name
end

#open_statusObject

Returns the value of attribute open_status.



2
3
4
# File 'lib/auto_service_cli/service_center.rb', line 2

def open_status
  @open_status
end

#paymentObject

Returns the value of attribute payment.



2
3
4
# File 'lib/auto_service_cli/service_center.rb', line 2

def payment
  @payment
end

#phone_numberObject

Returns the value of attribute phone_number.



2
3
4
# File 'lib/auto_service_cli/service_center.rb', line 2

def phone_number
  @phone_number
end

#ratingObject

Returns the value of attribute rating.



2
3
4
# File 'lib/auto_service_cli/service_center.rb', line 2

def rating
  @rating
end

#servicesObject

Returns the value of attribute services.



2
3
4
# File 'lib/auto_service_cli/service_center.rb', line 2

def services
  @services
end

#sloganObject

Returns the value of attribute slogan.



2
3
4
# File 'lib/auto_service_cli/service_center.rb', line 2

def slogan
  @slogan
end

#working_hoursObject

Returns the value of attribute working_hours.



2
3
4
# File 'lib/auto_service_cli/service_center.rb', line 2

def working_hours
  @working_hours
end

Class Method Details

.allObject



74
75
76
# File 'lib/auto_service_cli/service_center.rb', line 74

def self.all
  @@all.dup.freeze
end

.create(name) ⇒ Object



24
25
26
# File 'lib/auto_service_cli/service_center.rb', line 24

def self.create(name)
  self.new(name).tap { |center| center.save }
end

.reset_all!Object

Class mehods



70
71
72
# File 'lib/auto_service_cli/service_center.rb', line 70

def self.reset_all!
  @@all.clear
end

Instance Method Details

#details_from_hash(details) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/auto_service_cli/service_center.rb', line 34

def details_from_hash(details)
  # modify hash's rating
  if details.include?(:rating)
    details[:rating] = format_rating(details[:rating])
  end

  details.each do |detail, value|
    self.send("#{detail}=", value)
  end
end

#format_rating(rating) ⇒ Object

ex [“two”, “half”] or [“two”]



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/auto_service_cli/service_center.rb', line 46

def format_rating(rating)
  case rating[0]
    when "one"
      new_rating = "1"
    when "two"
      new_rating = "2"
    when "three"
      new_rating = "3"
    when "four"
      new_rating = "4"
    when "five"
      new_rating = "5"
    else
      # assume it's already formatted
      return rating
  end

  # TODO
  new_rating << ".5" if rating.size == 2 && rating.last == "half"
  new_rating + " star(s)"
end

#saveObject

Instance methods.



30
31
32
# File 'lib/auto_service_cli/service_center.rb', line 30

def save
  @@all << self
end