Class: SpreeCmCommissioner::Transit::ServiceCalendarForm

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/spree_cm_commissioner/transit/service_calendar_form.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ ServiceCalendarForm

Returns a new instance of ServiceCalendarForm.



20
21
22
23
# File 'lib/spree_cm_commissioner/transit/service_calendar_form.rb', line 20

def initialize(attrs = {})
  super
  @exception_rules ||= []
end

Instance Attribute Details

#end_dateObject

Returns the value of attribute end_date.



8
9
10
# File 'lib/spree_cm_commissioner/transit/service_calendar_form.rb', line 8

def end_date
  @end_date
end

#exception_rulesObject

Returns the value of attribute exception_rules.



8
9
10
# File 'lib/spree_cm_commissioner/transit/service_calendar_form.rb', line 8

def exception_rules
  @exception_rules
end

#fridayObject

Returns the value of attribute friday.



8
9
10
# File 'lib/spree_cm_commissioner/transit/service_calendar_form.rb', line 8

def friday
  @friday
end

#mondayObject

Returns the value of attribute monday.



8
9
10
# File 'lib/spree_cm_commissioner/transit/service_calendar_form.rb', line 8

def monday
  @monday
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/spree_cm_commissioner/transit/service_calendar_form.rb', line 8

def name
  @name
end

#saturdayObject

Returns the value of attribute saturday.



8
9
10
# File 'lib/spree_cm_commissioner/transit/service_calendar_form.rb', line 8

def saturday
  @saturday
end

#start_dateObject

Returns the value of attribute start_date.



8
9
10
# File 'lib/spree_cm_commissioner/transit/service_calendar_form.rb', line 8

def start_date
  @start_date
end

#sundayObject

Returns the value of attribute sunday.



8
9
10
# File 'lib/spree_cm_commissioner/transit/service_calendar_form.rb', line 8

def sunday
  @sunday
end

#thursdayObject

Returns the value of attribute thursday.



8
9
10
# File 'lib/spree_cm_commissioner/transit/service_calendar_form.rb', line 8

def thursday
  @thursday
end

#tuesdayObject

Returns the value of attribute tuesday.



8
9
10
# File 'lib/spree_cm_commissioner/transit/service_calendar_form.rb', line 8

def tuesday
  @tuesday
end

#wednesdayObject

Returns the value of attribute wednesday.



8
9
10
# File 'lib/spree_cm_commissioner/transit/service_calendar_form.rb', line 8

def wednesday
  @wednesday
end

Class Method Details

.from_service_calendar(calendar) ⇒ Object

Create form from ServiceCalendar ActiveRecord object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/spree_cm_commissioner/transit/service_calendar_form.rb', line 26

def self.from_service_calendar(calendar)
  return new if calendar.blank?

  new(
    name: calendar.name,
    start_date: calendar.start_date,
    end_date: calendar.end_date,
    monday: calendar.monday,
    tuesday: calendar.tuesday,
    wednesday: calendar.wednesday,
    thursday: calendar.thursday,
    friday: calendar.friday,
    saturday: calendar.saturday,
    sunday: calendar.sunday,
    exception_rules: calendar.exception_rules || []
  )
end

Instance Method Details

#weekdaysObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/spree_cm_commissioner/transit/service_calendar_form.rb', line 44

def weekdays
  {
    'monday' => monday,
    'tuesday' => tuesday,
    'wednesday' => wednesday,
    'thursday' => thursday,
    'friday' => friday,
    'saturday' => saturday,
    'sunday' => sunday
  }
end

#weekdays=(hash) ⇒ Object



56
57
58
59
60
61
62
63
64
65
# File 'lib/spree_cm_commissioner/transit/service_calendar_form.rb', line 56

def weekdays=(hash)
  hash = hash.transform_keys(&:to_s)
  @monday = cast_bool(hash['monday'])
  @tuesday = cast_bool(hash['tuesday'])
  @wednesday = cast_bool(hash['wednesday'])
  @thursday = cast_bool(hash['thursday'])
  @friday = cast_bool(hash['friday'])
  @saturday = cast_bool(hash['saturday'])
  @sunday = cast_bool(hash['sunday'])
end