Class: Class

Inherits:
Object
  • Object
show all
Defined in:
lib/chronic-rails.rb

Instance Method Summary collapse

Instance Method Details

#chronic_attr(attr_name, type = :time) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/chronic-rails.rb', line 10

def chronic_attr(attr_name,type=:time)
  attr_name = attr_name.to_s       
   class_eval %Q(
     def #{attr_name}=(val)  
       if val.class == String
         self[:#{attr_name}] = Chronic.parse(val).to_#{type.to_s}
       else
         self[:#{attr_name}] = val
       end
     end  
   )
end

#chronic_date(attr_name) ⇒ Object



4
5
6
# File 'lib/chronic-rails.rb', line 4

def chronic_date(attr_name)  
   chronic_attr(attr_name,:date) 
end

#chronic_time(attr_name) ⇒ Object



7
8
9
# File 'lib/chronic-rails.rb', line 7

def chronic_time(attr_name)  
  chronic_attr(attr_name)
end