Module: Parsefiles::Utils::ClassMethods

Defined in:
lib/parsefiles/utils.rb

Instance Method Summary collapse

Instance Method Details

#date_in_range(date, start_date, end_date) ⇒ Object



24
25
26
27
28
29
# File 'lib/parsefiles/utils.rb', line 24

def date_in_range(date,start_date,end_date)
  start = strDate_to_unix_timestamp(start_date)
  finish = strDate_to_unix_timestamp(end_date) + 86399
  range = start..finish
  range === date
end

#strDate_to_unix_timestamp(strDate) ⇒ Object



14
15
16
# File 'lib/parsefiles/utils.rb', line 14

def strDate_to_unix_timestamp(strDate)
  Date.strptime(strDate, '%m-%d-%Y').to_time.to_i
end

#unix_ts(file) ⇒ Object



10
11
12
# File 'lib/parsefiles/utils.rb', line 10

def unix_ts(file)
  File.mtime(file).to_i
end

#validate_date_format(strDate) ⇒ Object



18
19
20
21
22
# File 'lib/parsefiles/utils.rb', line 18

def validate_date_format(strDate)
  Date.strptime(strDate,'%m-%d-%Y')
  rescue ArgumentError
    raise "Invalid date format. Correct format : m-d-y."
end