Time for a bit of math. Let's define the following:

RubyDamage : The damage-per-attack added by imbuing a ruby

: The damage-per-attack added by imbuing a ruby EmeraldCritDamage : The percentage of damage-increase due to a critical hit added by imbuing an emerald

: The percentage of damage-increase due to a critical hit added by imbuing an emerald AttackSpeed : Your attacks-per-second

: Your attacks-per-second WeaponDamage : Your current damage-per-attack (including bonuses, like from your primary stat)

: Your current damage-per-attack (including bonuses, like from your primary stat) CritChance : Your current percentage (from 0 to 1) per hit of getting a critical-hit.

: Your current percentage (from 0 to 1) per hit of getting a critical-hit. CritDamage: Percentage of damage-increase due to a critical hit

Using a ruby will add

RubyDamage * AttackSpeed * (1 + CritChance*CritDamage)

to your total expected DPS, while using an emerald will add

WeaponDamage * AttackSpeed * (CritChance)(EmeraldCritDamage)

to it. You only want to use a Ruby if the first expression is larger than the second expression; that is,

(first expression) > (second expression) RubyDamage*AttackSpeed*(1 + CritChance*CritDamage) > WeaponDamage*AttackSpeed*(CritChance)(EmeraldCritDamage) RubyDamage*(1 + CritChance*CritDamage)/(CritChance*EmeraldCritDamage) > WeaponDamage

Thus you only want to imbue a ruby if the expression

RubyDamage*(1 + CritChance*CritDamage)/(CritChance*EmeraldCritDamage)

is greater than your weapon damage+bonuses. Note that this damage will increase as your primary stat goes up, so in general the emerald is the better choice for the long-run. Notice also this equation does not depend on your attack speed at all.

[Edit] To make this easier to make sense of, I've created a graph:

How to read this graph:

First, find your critical-hit damage% and critical-hit chance% (as shown on your detail tab in-game). Find that value on the above chart, and get its approximate value.

Next, take your damage (as shown on your character sheet) and divide by your attacks per second (as shown in the "details" tab).

If your damage (divided by attack rate) is larger than the graph-number, use an Emerald. But if the damage is smaller than the graph-number, use a Ruby. If they are approximately the same, you could use either, but I would recommend an Emerald, since it will scale better as your damage goes up.

The above chart is for Flawless Square gems. The other gems are largely similar:

So, in general, if you have low damage and low crit-chance, use a ruby; if you have high damage or high crit-chance, use an emerald (though if you have high crit-chance but low damage, you might want to double-check here).