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

#data_type, #form, #hidden, #hint, #invalid, #label, #required, #type

Attributes inherited from Element

#attrib, #force_closing_tag, #parent, #tag

Instance Method Summary collapse

Methods inherited from Form_Field

#disable!, #disabled=, #editable!, #enable!, #hidden?, #hide!, #invalid!, #invalid?, #optional!, #readonly!, #readonly=, #readonly?, #readonly_element, #required!, #required?, #show!, #to_hidden_field, #to_s

Methods inherited from Element

#+, #<<, #[], #[]=, #add_class, #clear_floating, #css_classes, #find_by_dom_id, #get_content, #has_content?, #id, #id=, #method_missing, #recurse, #remove_class, #set_content, #string, #swap, #to_ary, #type=

Methods included from Marshal_Helper_Class_Methods

#marshal_load

Methods included from Marshal_Helper

#marshal_dump

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
24
25
26
27
# 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]
  @year_range  ||= (2009..2020)

  if params[:value] then set_date(params[:value]) end

  params.delete(:value)
  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



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/aurita-gui/form/date_field.rb', line 54

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



94
95
96
# File 'lib/aurita-gui/form/date_field.rb', line 94

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

#value=(date) ⇒ Object Also known as: set_date



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/aurita-gui/form/date_field.rb', line 71

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, "%Y%m%d")
    @value = { :year  => date.year, 
               :month => date.month, 
               :day   => date.day }
  else
  end
  @year, @month, @day = @value[:year], @value[:month], @value[:day]
end