Module: Achoo::Achievo

Defined in:
lib/achoo/achievo.rb,
lib/achoo/achievo/table.rb,
lib/achoo/achievo/date_field.rb,
lib/achoo/achievo/login_form.rb,
lib/achoo/achievo/lock_month_form.rb,
lib/achoo/achievo/hour_registration_form.rb,
lib/achoo/achievo/hour_administration_form.rb,
lib/achoo/achievo/hour_registration_form_ranged.rb

Defined Under Namespace

Modules: LoginForm Classes: HourAdministrationForm, HourRegistrationForm, HourRegistrationFormRanged, LockMonthForm, Table

Class Method Summary collapse

Class Method Details

.DateField(attr_name, field_name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/achoo/achievo/date_field.rb', line 6

def self.DateField(attr_name, field_name)
  Module.new do
    define_method("#{attr_name}=") do |date|
      # Day and month must be prefixed with '0' if single
      # digit. Date.day and Date.month doesn't do this. Use strftime
      send("#{attr_name}_day_field=",   date.strftime('%d'))
      send("#{attr_name}_month_field=", date.strftime('%m'))
      send("#{attr_name}_year_field=",  date.year)
    end
    
    define_method("#{attr_name}") do
      Date.new(*[send("#{attr_name}_year_field"),
                 send("#{attr_name}_month_field"),
                 send("#{attr_name}_day_field")].collect {|e| e.to_i})
    end
    
    %w(day month year).each do |e|
      define_method("#{attr_name}_#{e}_field") do
        @form.field_with(:name => "#{field_name}[#{e}]").value
      end 
          
      define_method("#{attr_name}_#{e}_field=") do |val|
        @form.field_with(:name => "#{field_name}[#{e}]").value = val
      end 
    end
  end
end