Calvin is a human incarnation of the Doctor who got lost and never opened the pocket watch after whatever he was originally created for was resolved. He was a Teen Genius, as one could expect from the Doctor, and he writes as an outlet for his overactive subconsciously Time Lord mind, as the Doctor did in "Human Nature" and "The Family of Blood". He even dreams of his past as the Doctor did — Ruby was actually his old companion, whom he lost before becoming human and so continues to dream about, just as he did with Rose, and consequently, he writes about her. The Ruby of the film, however, is the Rani, who found out that the Doctor was trapped on Earth in a human body without his Time Lord memories, and decided to use this as a royal opportunity to screw with him. Once she realised he was dreaming about his old companion Ruby - whom she may have even killed - she regenerated, tailoring her new incarnation to be like the Ruby of the Doctor's dreams. Then she planted "Calvin's" typewriter, which is actually a sophisticated piece of technology that reports back to her whatever he types, allowing her to play along and create the illusion that Calvin is in control. At the end of the film, when Calvin sets Ruby free, her actions are still just keeping up the illusion, and she plans to torment the Doctor for as long as possible until he dies, she gets bored and kills him, or he accidentally finds and opens the pocket watch
Rather, Ruby is based on a vision Calvin had of his future wife. His muse took on human form to help him work out his issues to prepare him for her.
- The woman at the end *is* indeed Ruby, as confirmed by the actual script itself.
From the time Calvin's therapist tells him to write out his issues to the time Calvin is releasing his book, IS the content of his book. Through the process of writing his novel, Calvin confronted his own dark tendencies, and by the time of publication has become the better for it. Ruby has never been anything other than a written character on the page, and the woman he encounters after his book release is NOT Ruby. She looks strikingly like the character he had envisioned, but is a whole, REAL person that he now understands deserves love and respect.