This looks almost correct, but if am I mistaken, won't the logic of this 'if' always apply even for the empty case which the next is meant to catch? Since hash[:name] == nil or '' will match this expression first ...

You almost want to do:

    if ! hash[:name]
      ...
    elsif not /^ ... / =~ hash[:name]
      ..
    end

Don't you? Otherwise cases without a comment will just get a number, without the hexdigest to fill out the text.