Hi. I’m new to Ruby and I like it. But even after digesting all the good
documentation, when I started a small project for planning my day, I ran
into a few problems. Let me explain.
I want a script that I can run any time which will basically give
messages based on system time and date. For each day, I have two
“sessions”. So, if it’s the 10AM-12AM session of Monday, the message
will be “WPD work”. If it is 5PM-7PM session of Friday, the program will
message “WordPress work” and so on.
It’s basically like a database.
Now, for this, I want to use conditional if statements (suggest if
there’s a better way ). So I don’t know much about how to play with time
and date, so here’s a rough sketch of what I want to do:
if day=Monday do puts “WPD work” end
I know it’s not that simple. I also tried other approaches like:
time=Time.new
puts"\t\t\tToday:"+time.strftime("%a")
But then I don’t know how to use this returned data value for further
processing, like the below snippet doesn’t work:
if time.strftime("%a")=“Friday” do puts “WordPress work” end
Using this in this way doesn’t even make sense anyway. I just tried. As
I said, I’m completely unfamiliar with handling system date and type.
Suppose I opt for user-input:
day=gets.chomp
So you see, it’s SO simple. All I need is a time-range and day name to
proceed further. That’s ALL. But I seem to be unable to get that
automatically from system.