Class: Formatic::Date

Inherits:
Base show all
Defined in:
app/components/formatic/date.rb

Overview

Date/calendar

Defined Under Namespace

Classes: Day

Instance Method Summary collapse

Methods inherited from Base

#input_name, #param_key, #value, #wrapper

Methods inherited from ApplicationComponent

#initialize

Constructor Details

This class inherits a constructor from Formatic::ApplicationComponent

Instance Method Details

#calendar(now: Time.current) ⇒ Object



80
81
82
83
84
85
86
87
# File 'app/components/formatic/date.rb', line 80

def calendar(now: Time.current)
  from = 5.days.ago.to_date
  till = now.beginning_of_month.advance(months: 2).end_of_month.to_date

  (from..till).map do |date|
    ::Formatic::Date::Day.new(date:)
  end
end

#css_classesObject



36
37
38
# File 'app/components/formatic/date.rb', line 36

def css_classes
  %i[c-formatic-date__input]
end

#day_attribute_nameObject



52
53
54
# File 'app/components/formatic/date.rb', line 52

def day_attribute_name
  "#{f.object.model_name.param_key}[#{attribute_name}(3i)]"
end

#day_input_idObject



68
69
70
# File 'app/components/formatic/date.rb', line 68

def day_input_id
  "#{f.object.model_name.param_key}_#{attribute_name}_3i"
end

#day_valueObject



64
65
66
# File 'app/components/formatic/date.rb', line 64

def day_value
  f.object.public_send(attribute_name)&.day
end

#month_attribute_nameObject



56
57
58
# File 'app/components/formatic/date.rb', line 56

def month_attribute_name
  "#{f.object.model_name.param_key}[#{attribute_name}(2i)]"
end

#month_input_idObject



72
73
74
# File 'app/components/formatic/date.rb', line 72

def month_input_id
  "#{f.object.model_name.param_key}_#{attribute_name}_2i"
end

#options_for_dayObject



40
41
42
# File 'app/components/formatic/date.rb', line 40

def options_for_day
  options_for_select collection_for_day, day_value
end

#options_for_monthObject



44
45
46
# File 'app/components/formatic/date.rb', line 44

def options_for_month
  options_for_select collection_for_month, f.object.public_send(attribute_name)&.month
end

#options_for_yearObject



48
49
50
# File 'app/components/formatic/date.rb', line 48

def options_for_year
  options_for_select collection_for_year, f.object.public_send(attribute_name)&.year
end

#year_attribute_nameObject



60
61
62
# File 'app/components/formatic/date.rb', line 60

def year_attribute_name
  "#{f.object.model_name.param_key}[#{attribute_name}(1i)]"
end

#year_input_idObject



76
77
78
# File 'app/components/formatic/date.rb', line 76

def year_input_id
  "#{f.object.model_name.param_key}_#{attribute_name}_1i"
end