Class: Aurita::GUI::Date_Field

Inherits:
Form_Field show all
Defined in:
lib/aurita-gui/form/date_field.rb

Direct Known Subclasses

Datetime_Field

Instance Attribute Summary collapse

Attributes inherited from Form_Field

#form, #label, #type

Attributes inherited from Element

#attrib, #content, #parent, #tag, #type

Instance Method Summary collapse

Methods inherited from Form_Field

#disable!, #editable!, #enable!, #readonly!, #readonly?, #readonly_element, #to_s

Methods inherited from Element

#+, #[], #[]=, #clear_floating, #dom_id, #dom_id=, #each, #empty?, #id, #id=, #length, #method_missing, #string, #to_ary

Constructor Details

#initialize(params, &block) ⇒ Date_Field

Returns a new instance of Date_Field.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/aurita-gui/form/date_field.rb', line 11

def initialize(params, &block)
  @date_format   = params[:date_format]
  @date_format ||= 'mdy'
  @year_range    = params[:year_range]

  params.delete(:date_format)
  params.delete(:date)
  params.delete(:day)
  params.delete(:month)
  params.delete(:year)
  params.delete(:year_range)
  super(params, &block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Aurita::GUI::Element

Instance Attribute Details

#date_formatObject

Returns the value of attribute date_format.



9
10
11
# File 'lib/aurita-gui/form/date_field.rb', line 9

def date_format
  @date_format
end

#dayObject

Returns the value of attribute day.



9
10
11
# File 'lib/aurita-gui/form/date_field.rb', line 9

def day
  @day
end

#day_elementObject

Returns the value of attribute day_element.



9
10
11
# File 'lib/aurita-gui/form/date_field.rb', line 9

def day_element
  @day_element
end

#monthObject

Returns the value of attribute month.



9
10
11
# File 'lib/aurita-gui/form/date_field.rb', line 9

def month
  @month
end

#month_elementObject

Returns the value of attribute month_element.



9
10
11
# File 'lib/aurita-gui/form/date_field.rb', line 9

def month_element
  @month_element
end

#yearObject

Returns the value of attribute year.



9
10
11
# File 'lib/aurita-gui/form/date_field.rb', line 9

def year
  @year
end

#year_elementObject

Returns the value of attribute year_element.



9
10
11
# File 'lib/aurita-gui/form/date_field.rb', line 9

def year_element
  @year_element
end

#yearsObject

Returns the value of attribute years.



9
10
11
# File 'lib/aurita-gui/form/date_field.rb', line 9

def years
  @years
end

Instance Method Details

#elementObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/aurita-gui/form/date_field.rb', line 50

def element
  select_fields = []
  @date_format.scan(/./).each { |c|
    case c
    when 'y' then
      select_fields << year_element() 
    when 'm' then
      select_fields << month_element() 
    when 'd' then
      select_fields << day_element() 
    end
  }
  HTML.div(@attrib) { 
    select_fields
  }
end

#valueObject



88
89
90
# File 'lib/aurita-gui/form/date_field.rb', line 88

def value
  { :day => @day, :month => @month, :year => @year }
end

#value=(date) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/aurita-gui/form/date_field.rb', line 67

def value=(date)
  case date 
  when Hash then
    @value = date
  when Datetime then
    @value = { :year  => date.year, 
               :month => date.month, 
               :day   => date.day }
  when Date then
    @value = { :year  => date.year, 
               :month => date.month, 
               :day   => date.day }
  when String then
    date = Datetime.strptime(date)
    @value = { :year  => date.year, 
               :month => date.month, 
               :day   => date.day }
  else
  end
end