lib/metoffice_datapoint/mash.rb
def convert_value(val, duping=false) #:nodoc:
      case val
        when self.class
          val.dup
        when ::Hash
          val = val.dup if duping
          self.class.new(val)
        when Array
          val.collect{ |e| convert_value(e) }
        else
          if val.class == String
            begin
              datetime_regexp = /^[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}T[[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}Z?$/
              return DateTime.parse(val) if datetime_regexp.match(val)
              date_regexp = /^[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}Z?$/
              return Date.parse(val) if date_regexp.match(val)
            rescue
              # no Date or DateTime found, keep calm and carry on
            end
            val
          else
            val
          end
      end
    end
def convert_value(val, duping=false) #:nodoc:
      case val
        when self.class
          val.dup
        when ::Hash
          val = val.dup if duping
          self.class.new(val)
        when Array
          val.collect{ |e| convert_value(e) }
        else
          if val.class == String
            begin
              datetime_regexp = /^[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}T[[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}Z?$/
              return DateTime.parse(val) if datetime_regexp.match(val)
              date_regexp = /^[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}Z?$/
              return Date.parse(val) if date_regexp.match(val)
            rescue
              # no Date or DateTime found, keep calm and carry on
            end
            val
          else
            val
          end
      end
    end
Protected: Unlike its parent Mash, this Mash will convert other Hashie::Hash values to a Mash when assigning
 instead of respecting the existing subclass. Also converts Strings parseable by Date(Time).parse to Date(Time)
 objects.
 Overloads the the convert_value Mash method.

 val - Object to be converted.

 Examples:
   convert_value(#<Array ...>) => recursively calls itself to convert values in Array
   convert_value(#<::Hash ...>) => Mash.new(#<::Hash ...>)
   convert_value("my string") => "my string"
   convert_value("2013-06-10T12:00:00Z") => #<DateTime: 2013-06-10T12:00:00Z ...>
   convert_value("2013-06-10T12:00:00") => #<DateTime: 2013-06-10T12:00:00Z ...>
   convert_value("2013-06-10Z") => #<Date: 2013-06-10 ...>
   convert_value("2013-06-10") => #<Date: 2013-06-10 ...>

 Returns Objects of different types, depending on the original val passed in.