Class: RestaurantTypes::Normal

Inherits:
Object
  • Object
show all
Defined in:
app/my_lib/restaurant_types/normal.rb

Overview

Used for set restaurant as normal restaurant Validate the required fields are expected by call #valid?

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(restaurant_id) ⇒ Normal

Returns a new instance of Normal.



12
13
14
15
16
# File 'app/my_lib/restaurant_types/normal.rb', line 12

def initialize(restaurant_id)
  self.restaurant = Restaurant.find(restaurant_id)
  @errors = ActiveModel::Errors.new(self)
  self
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



30
31
32
# File 'app/my_lib/restaurant_types/normal.rb', line 30

def errors
  @errors
end

#restaurantObject

Returns the value of attribute restaurant.



10
11
12
# File 'app/my_lib/restaurant_types/normal.rb', line 10

def restaurant
  @restaurant
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
27
28
# File 'app/my_lib/restaurant_types/normal.rb', line 18

def valid?
  if ChargeImmediately.new(restaurant.id).valid?
    errors.add(:base, 'This Restaurant will charge CC immediately')
    false
  elsif ChargeOnHold.new(restaurant.id).valid?
    errors.add(:base, 'This Restaurant will charge CC on hold')
    false
  else
    true
  end
end