Method: Google#convert

Defined in:
lib/musicscrape.rb

#convert(event_date) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/musicscrape.rb', line 98

def convert(event_date)
  #convert a stranger date to a google date
  #find out what day of the week today is
  #assume that Sun...Sat are the next one
  #{0=>'Sun', 1=>'Mon', 2=>'Tues', 3=>'Wed', 4=>'Thurs', 5=> 'Fri', 6=>'Sat', 
  day_array=[0,1,2,3,4,5,6] #to make subtracted days of week wrap around
  day_hash = {:Sun=>0,:Mon=>1,:Tue=>2, :Wed=>3,:Thurs=>4,:Fri=>5,:Sat=>6}
  month_hash = {:Jan=>1, :Feb=>2, :Mar=>3, :Apr=>4, :May=>5, :Jun=>6, :Jul=>7, :Aug=>8, :Sep=>9,:Oct=>10, :Nov=>11, :Dec=>12 }
  current_time = Time.now
  current_day = current_time.wday
  date_array = event_date.split(" ")
  if date_array.size == 3
    #if it's 3 words assume the format is Day Month Date
    event_day = day_hash[date_array[0].capitalize.to_sym]
    event_month = month_hash[date_array[1].capitalize.to_sym]
    event_date = date_array[2].to_i
    event_time = Time.local(current_time.year,event_month,event_date)
  else
    #it's going to be in the form 'Every Mon' but we will only put it on for this week
    event_day = day_hash[date_array[1].capitalize.to_sym] #find the number 0 to 6 for event day
    event_time = current_time + (60*60*24*day_array[event_day - current_day])#get the differential from todays day
  end
  event_time
end