[#385051] How to order Structs based on two fields — Iñaki Baz Castillo <ibc@...>

Hi, I've a struct like this:

20 messages 2011/07/01
[#385052] Re: How to order Structs based on two fields — Iñaki Baz Castillo <ibc@...> 2011/07/01

2011/7/1 I=C3=B1aki Baz Castillo <ibc@aliax.net>:

[#385057] Re: How to order Structs based on two fields — Robert Klemme <shortcutter@...> 2011/07/01

On Fri, Jul 1, 2011 at 12:55 PM, I=F1aki Baz Castillo <ibc@aliax.net> wrote=

[#385069] Offering Help — Joe Peric <peric.joe@...>

I'm new to Ruby and I am willing to learn. Anyone need help on a

18 messages 2011/07/01
[#385072] Re: Offering Help — Jeremy Heiler <jeremyheiler@...> 2011/07/01

On Fri, Jul 1, 2011 at 11:43 AM, Joe Peric <peric.joe@gmail.com> wrote:

[#385073] Re: Offering Help — Joe Peric <peric.joe@...> 2011/07/01

Never heard of it, but I'll get right on it. Thanks.

[#385082] Re: Offering Help — Joe Peric <peric.joe@...> 2011/07/02

Just finished this. I had to find some more info on exceptions to get

[#385083] Re: Offering Help — Jeremy Heiler <jeremyheiler@...> 2011/07/02

On Sat, Jul 2, 2011 at 1:39 PM, Joe Peric <peric.joe@gmail.com> wrote:

[#385102] symbol vs string for hash keys — Intransition <transfire@...>

What are the important factors to consider when deciding whether to

12 messages 2011/07/03

[#385160] Fatal Error with Ruby/GTK2, Homebrew, Green Shoes, and OSX Snow Leopard — Timothy Barnes <barnes7td@...>

I posted the below question to the Shoes mailing list and got back the

10 messages 2011/07/09

[#385194] RubyInstaller Extras — Jon <jon.forums@...>

Since 2009, we've been pleased to include Huw Collingbourne's The Book of Ruby with RubyInstaller. Well now, Huw has a newly updated version, and he's published it with No Starch Press.

11 messages 2011/07/12

[#385207] Creating a range of directories — Simon Harrison <simon@...>

I'm wanting to create a range of directories with a prefix, like the

13 messages 2011/07/13

[#385276] Is there a more efficient way to remove data from a string? — Eddie Catflap <catflaporama@...>

Hi

9 messages 2011/07/15

[#385297] Help needed for a new release of text-hyphen — Austin Ziegler <halostatue@...>

I've had folks asking me for a release of text-hyphen that works with

12 messages 2011/07/15

[#385326] Comparing hashes based on their keys — Stefano Mioli <stefano.mioli@...>

Hi list,

13 messages 2011/07/15

[#385342] moving a 1.8.6 install? — Roggie Boone <rogboone@...>

Is it possible to move the gems from a Ruby 1.8.6 install on an (old)

10 messages 2011/07/15

[#385410] Better name for #zip_with — Intransition <transfire@...>

Any ideas for a better name for:

13 messages 2011/07/18

[#385452] Ruby + USB + CCTV Camera Driver? — "Bob Carpenter." <rgc3679@...>

I want to write a Ruby driver that handles the feed from A CCTV camera.

23 messages 2011/07/18
[#385459] Re: Ruby + USB + CCTV Camera Driver? — William Rutiser <wruyahoo05@...> 2011/07/18

On 2011-07-18 1:00 PM, Bob Carpenter. wrote:

[#385461] Re: Ruby + USB + CCTV Camera Driver? — "Bob Carpenter." <rgc3679@...> 2011/07/18

William Rutiser wrote in post #1011466:

[#385462] Re: Ruby + USB + CCTV Camera Driver? — Hassan Schroeder <hassan.schroeder@...> 2011/07/18

On Mon, Jul 18, 2011 at 11:51 AM, Bob Carpenter. <rgc3679@yahoo.com> wrote:

[#385464] Re: Ruby + USB + CCTV Camera Driver? — "Bob Carpenter." <rgc3679@...> 2011/07/18

Hassan Schroeder wrote in post #1011472:

[#385471] Re: Ruby + USB + CCTV Camera Driver? — Hassan Schroeder <hassan.schroeder@...> 2011/07/18

On Mon, Jul 18, 2011 at 12:58 PM, Bob Carpenter. <rgc3679@yahoo.com> wrote:

[#385474] Re: Ruby + USB + CCTV Camera Driver? — Phillip Gawlowski <cmdjackryan@...> 2011/07/18

On Tue, Jul 19, 2011 at 12:18 AM, Hassan Schroeder

[#385477] Re: Ruby + USB + CCTV Camera Driver? — "Bob Carpenter." <rgc3679@...> 2011/07/19

Phillip Gawlowski wrote in post #1011503:

[#385509] A beginner question. — "Cajus A." <cajus_@...>

Hi i'm trying to write and example program where you speak to a

12 messages 2011/07/19

[#385542] Splitting strings — Ryan Mckenzie <ryan@...>

Hi all,

18 messages 2011/07/19

[#385565] error building ruby p290 — Dev Guy <devguy.ca@...>

I get the following build error on my Linux box while trying to build

12 messages 2011/07/20

[#385629] Are Job Ads OK? — Lee Hughes <lee@...>

Is it OK to post Ruby job ads on this forum?

12 messages 2011/07/21

[#385847] String manuplation example — kotin 76 <kotin76@...>

Hi,

15 messages 2011/07/27

[#385860] Counting lines of code in a ruby code file ignoring method code lines in the process — Harry Truax <htruax@...>

Hello,

8 messages 2011/07/27

[#385936] Help in Pointer — Tridib Bandopadhyay <tridib04@...>

Hello

18 messages 2011/07/29

[#386012] Ruby a "4th generation language"? Credible sources? — Albert Schlef <albertschlef@...>

I've noticed that Wikipedia says that "C#, Java" are 3'rd generation

13 messages 2011/07/31

[#386050] system stack error in ObjectSpace.each_object — luke gruber <luke.gru@...>

Hey guys, I'm just starting to mess around with metaprogramming in Ruby,

14 messages 2011/07/31
[#386052] Re: system stack error in ObjectSpace.each_object — Josh Cheek <josh.cheek@...> 2011/07/31

On Sun, Jul 31, 2011 at 4:29 PM, luke gruber <luke.gru@gmail.com> wrote:

[#386055] Re: system stack error in ObjectSpace.each_object — luke gruber <luke.gru@...> 2011/08/01

> Typically, SystemStackError is due to recursing for too long, perhaps I

[#386058] Re: system stack error in ObjectSpace.each_object — Robert Klemme <shortcutter@...> 2011/08/01

On Mon, Aug 1, 2011 at 3:56 AM, luke gruber <luke.gru@gmail.com> wrote:

Re: Renages

From: Rob Biedenharn <Rob@...>
Date: 2011-07-05 17:34:16 UTC
List: ruby-talk #385134
On Jul 2, 2011, at 4:37 PM, Peter Hicks wrote:

> All,
>
> I have a requirement to translate a time between 0000 and 2359 in to a
> single character 'interval ID' based on the time.  For example, if the
> time is between 0000 and 0059, '0' should be returned, if it's between
> 0100 and 0159, '1' should be return.  The problem is that 0700-0729
> should return 'A', 0730-0759 should return 'B', i.e. it's not a simple
> mapping.
>
> I have the following, but I can't help thinking there's a much more
> efficient way of doing it - can anyone advise, as I'm a little stuck!
>
>  xlate = [ [ '0000', '0059', '0' ], [ '0100', '0159', '1' ],
>            [ '0200', '0259', '2' ], [ '0300', '0359', '3' ],
>            [ '0400', '0459', '4' ], [ '0500', '0559', '5' ],
>            [ '0600', '0659', '6' ], [ '0700', '0729', 'A' ],
>            [ '0730', '0759', 'B' ], [ '0800', '0829', 'C' ],
>            [ '0830', '0859', 'D' ], [ '0900', '0929', 'E' ],
>            [ '0930', '0959', 'F' ], [ '1000', '1029', 'G' ],
>            [ '1030', '1059', 'H' ], [ '1100', '1129', 'I' ],
>            [ '1130', '1159', 'J' ], [ '1200', '1229', 'K' ],
>            [ '1230', '1259', 'L' ], [ '1300', '1329', 'M' ],
>            [ '1330', '1359', 'N' ], [ '1400', '1429', 'O' ],
>            [ '1430', '1459', 'P' ], [ '1500', '1529', 'Q' ],
>            [ '1530', '1559', 'R' ], [ '1600', '1629', 'S' ],
>            [ '1630', '1659', 'T' ], [ '1700', '1729', 'U' ],
>            [ '1730', '1759', 'V' ], [ '1800', '1829', 'W' ],
>            [ '1830', '1859', 'X' ], [ '1900', '1959', 'Y' ],
>            [ '2000', '2059', 'Z' ], [ '2100', '2159', '7' ],
>            [ '2200', '2259', '8' ], [ '2300', '2359', '9' ] ]
>
>  xlate.each do |range|
>    return range[2] if time >= range[0] && time <= range[1]
>  end
>
> --  
> Peter Hicks <peter.hicks@poggs.co.uk>

You just need to check from the "end" on back and pick the first one  
that matches.

  xlate = [ [ '0000', '0' ], [ '0100', '1' ], [ '0200', '2' ],  
[ '0300', '3' ],
            [ '0400', '4' ], [ '0500', '5' ], [ '0600', '6' ],  
[ '0700', 'A' ],
            [ '0730', 'B' ], [ '0800', 'C' ], [ '0830', 'D' ],  
[ '0900', 'E' ],
            [ '0930', 'F' ], [ '1000', 'G' ], [ '1030', 'H' ],  
[ '1100', 'I' ],
            [ '1130', 'J' ], [ '1200', 'K' ], [ '1230', 'L' ],  
[ '1300', 'M' ],
            [ '1330', 'N' ], [ '1400', 'O' ], [ '1430', 'P' ],  
[ '1500', 'Q' ],
            [ '1530', 'R' ], [ '1600', 'S' ], [ '1630', 'T' ],  
[ '1700', 'U' ],
            [ '1730', 'V' ], [ '1800', 'W' ], [ '1830', 'X' ],  
[ '1900', 'Y' ],
            [ '2000', 'Z' ], [ '2100', '7' ], [ '2200', '8' ],  
[ '2300', '9' ],
            ].reverse
#  Note the .reverse here

time = Time.now.strftime('%H%M')
xlate.detect{|(start,code)| time >= start}

Then you can vary the start times and not be concerned about the  
"breaks" in the mapping or whether there is a 30-minute boundary. (And  
not build an 60x24 entry string or array of minutes even though that  
might be more efficient depending on how many lookups you need to do.)

-Rob

Rob Biedenharn		
Rob@AgileConsultingLLC.com	http://AgileConsultingLLC.com/
rab@GaslightSoftware.com		http://GaslightSoftware.com/


In This Thread