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



89
90
91
92
93
94
95
96
# File 'app/components/formatic/date.rb', line 89

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

#calendar?Boolean

Returns:

  • (Boolean)


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

def calendar?
  return false if show_calendar == false
  return false if discard_day

  true
end

#css_classesObject



42
43
44
# File 'app/components/formatic/date.rb', line 42

def css_classes
  i[c-formatic-date__input]
end

#day_attribute_nameObject



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

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

#day_input_idObject



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

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

#month_attribute_nameObject



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

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

#month_input_idObject



81
82
83
# File 'app/components/formatic/date.rb', line 81

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

#options_for_dayObject



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

def options_for_day
  options_for_select collection_for_day, f.object.public_send(attribute_name)&.day
end

#options_for_monthObject



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

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

#options_for_yearObject



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

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

#year_attribute_nameObject



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

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

#year_input_idObject



85
86
87
# File 'app/components/formatic/date.rb', line 85

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