lib/lazy_resource/resource.rb in lazy_resource-0.2.0 vs lib/lazy_resource/resource.rb in lazy_resource-0.3.0

- old
+ new

@@ -191,10 +191,22 @@ if (attribute_type.is_a?(::Array) && attribute_type.first.include?(LazyResource::Resource)) value = value.map { |v| v.as_json } elsif attribute_type.include?(LazyResource::Resource) value = value.as_json elsif attribute_type == DateTime - value = value.to_s + if options[:include_time_ago_in_words] && defined?(TwitterCldr) + hash[:"#{attribute_name}_in_words"] = (DateTime.now - (DateTime.now - value).to_f).localize.ago.to_s + end + + if options[:strftime] + value = self.send(attribute_name).strftime(options[:strftime]) + end + + if options[attribute_name.to_sym] && options[attribute_name.to_sym][:strftime] + value = self.send(attribute_name).strftime(options[attribute_name.to_sym][:strftime]) + end + + value = value.to_s unless value.is_a?(String) end hash[attribute_name.to_sym] = value end hash