Monday 27 August 2007

Truth in Fiction

So, I was having dinner with my cousin the other day[1]. Now my cousin and I are both part of an international book-swapping club, so we often swap books with each other, or chat about the books we're currently reading. Anyway, she had a book to lend me, and gave me a brief description of what it was about and why she liked it. What struck me was her use of the word "inoffensive" as a descriptive for the plot.

Now, I like to think I don't really judge a person by their book-taste. I mean everyone's different, and that's just fine. If you want to waste your time reading endless soppy romances, or brain-dead action books with no plot, but lots of sex... that's not my choice and doesn't impinge on my life one jot, so go for your life.

But it got me thinking about what it is that I *do* look for in a book. After all, my taste is, you could say "highly eclectic". I have fiction, non-fiction, fantasy, mysteries, science-fiction, speculative fiction, historical fabrications, and even the odd romance or action book.

With all that diversity, is it possible for there to be an overall theme running through here? Clearly not in genre, but the contrast with the word "inoffensive" really got me thinking.

I don't care if a book is offensive, what I value in a book is its sense of Truth.

Now, clearly I don't mean "it must be a true story" - after all, I read a hell of a lot of fiction (about 40-60 books a year on average). I also don't mean "it must mirror reality" as I read very little mainstream (the realm of "near reality" books) by comparison with my science fiction and fantasy.

After all, "The Lord of the Rings" has elves, and orcs and and magic rings galore, so you couldn't call is a true story, but in one sense it is a True Story. It thoroughly explores the reactions and relationships between the characters, and thereby delves into the Truth by exploring how to hold onto friendship through a struggle against near-overwhelming odds. About the Truth of courage, how it doesn't mean you are unafraid, but that you are prepared to struggle on for a cause that is worth fighting for, even when you are certain that you will not see the end of it.

It is this kind of Truth that I value in (what I consider to be) a good book.

Once I got onto that train of thought, I also realised why some other books really didn't appeal to me. I've recently tried to read my way through a few of the classic "Stainless Steel Rat" stories (by Harry Harrison). Mainly because several SF-fan friends of mine (mainly male) have enthused about how they loved them as kids. When I came to read them I found them to be bog-standard "boy's own adventure" stories... just set in space. Which were *so* not to my taste.

In the light of my new discovery I can see what was lacking in them that turned me off. A boy's own adventure works like a fantasy/day-dream. Everything goes just perfectly. Even when things are going wrong, you know that some Deus ex Machina is waiting in the wings to save the day. I get the same feeling from Traci Harding (though that is fantasy of the female kind).

Some authors bounce between the two ends. Laurell K Hamilton can push too far to the fantasy side of things, her recent books have this side clearly overshadowing the plot. Whereas her earlier books showed a great ability to get to the Truth of the relationships between the characters. Her main character (Anita Blake) is a vampire-hunter, hunting rogue vampires in a world where vampires have been made into "legitimate citizens". Unfortunately, vampires have several "natural" abilities that can cause problems in humans (especially those creating an irresistable "draw" or desire). Laurell writes poignantly about Anita's internal emotional struggle against the desire she feels for a particular vampire while simultaneously having to deal with the physical struggles she goes through in the course of her job.

Of course this also aparrently involves a lot of sex...

So, to get back to the original point, I wonder a bit about what my cousin meant by describing a book as "inoffensive". Inoffensive to what?

I can only guess that she meant inoffensive to her Christian values, and to her sense of well-being. Like many people, she probably doesn't want a provocative book that jolts her out of her current orbit. This is reasonable. She's a mother and definitely has a lot on her plate already... but this kind of thought-provoking, stimulating book is exactly what I crave.

So, I don't hold out a lot of faith that I'll really find her book to be as interesting as she finds it. But I'll definitely give it a go. Who knows? Maybe I'll be pleasantly surprised.

Notes

[1]Surjit's Indian Restaurant: 215 Parramatta Road Annandale (Sydney). I thoroughly recommend this place - they do fantastic Indian. Aparrently the Sri Lankan cricket team visits there when they are over here.

Thursday 9 August 2007

validates percentage

So, we wanted to check that a user could enter both "20" and "20%" and "20.000%" and have them all perfectly valid for a field on our models. I finished up with this validation method (below) to add to ActiveRecord::Base.

  # validates whether the given object is a percentage
  # Can also take optional args which will get passed verbatim into the
  # "validates inclusion" method.
  # It will safely take the usual set of fields for that - but if you pass
  # in a new message - it will get used for both validations.
  # The default message is: "should be a percentage (0-100)"
  def self.validates_percentage(fields, args = {})
    msg = args[:message] || "should be a percentage (0-100)"
    validates_each fields do |model, attr, val|
       pre_val = model.send("#{attr}_before_type_cast".to_sym)
       unless val.nil? || !pre_val.is_a?(String) || pre_val =~ /^[-+]?\d+(\.\d*)?%?$/
         model.errors.add(attr, msg) 
       end
     end
    args[:message] = msg
    args[:in] = 0..100 
    validates_inclusion_of fields, args 
  end