Please help me with this Ruby code

Posted by Bragaadeesh on Stack Overflow See other posts from Stack Overflow or by Bragaadeesh
Published on 2010-06-07T15:03:00Z Indexed on 2010/06/07 15:22 UTC
Read the original article Hit count: 162

Filed under:
|
|

Hi,

I am new to Ruby and I know that I am not using the simple and powerful methods available within it. I made my code work but it has to be simple not this huge (especially I feel I am very bad at loop variables)

i = 0
j = 0

loop_count = ((to_date-from_date)/(60*60*24)).to_i#diff b/w two dates in days

loop_count.times do
   48.times do

    event = Icalendar::Event.new

    status = get_availability_on_date_and_hour(@templates, @availabilities, from_date+j.days, i).downcase

    if(status != 'unavailable')
      #Initialize start and end dates in DateTime's civil format
      bias_date_time = DateTime.civil(from_date.year, from_date.month, from_date.day)

      event.dtstart = bias_date_time + j.day + (i/2).to_i.hour + (i%2*30).to_i.minutes
      event.dtend = event.dtstart + 30.minutes

      event.summary = status.upcase
      cal.add_event(event)
    end

    i += 1
  end
  i = 0
  j += 1
end

© Stack Overflow or respective owner

Related posts about ruby

Related posts about refactoring