+
+ class Element
+ class << self
+ def def_bang(name, chain)
+ class_eval %<
+ def #{name}!
+ blank2nil { #{chain.join(' rescue ')} rescue nil }
+ end
+ >, *get_file_and_line_from_caller(0)
+ end
+ end
+
+ {
+ :link => %w{link.href link},
+ :guid => %w{guid.content guid},
+ :content => %w{content.content content},
+ :description => %w{description.content description},
+ :title => %w{title.content title},
+ :category => %w{category.content category},
+ :dc_subject => %w{dc_subject},
+ :author => %w{author.name.content author.name author},
+ :dc_creator => %w{dc_creator}
+ }.each { |name, chain| def_bang name, chain }
+
+ protected
+ def blank2nil(&block)
+ x = yield
+ (x && !x.empty?) ? x : nil
+ end
+ end