lib/has_meta.rb in has_meta-0.0.2 vs lib/has_meta.rb in has_meta-0.0.3
- old
+ new
@@ -12,12 +12,18 @@
def has_meta(options = {})
options.each_pair do |meth, fields|
define_method("meta_#{meth}") {|*args|
length = args.first if args.is_a? Array
length ||= 255
- field = [*fields].detect{|f| send(f).present?}
- return nil if field.nil?
- str = send(field).to_s.strip
+
+ if fields.is_a? Proc
+ str = fields.call(self)
+ else
+ field = [*fields].detect{|f| send(f).present?}
+ return nil if field.nil?
+ str = send(field).to_s.strip
+ end
+
str.gsub!(' ', ' ')
str.gsub!(/<.*?>/, '')
str = ::CGI::unescapeHTML(str)
str = (str[0,length - 3] + '...') if str.size > length
str