Method: Hash#to_rel_attr
- Defined in:
- lib/html_attributes/hash.rb
#to_rel_attr ⇒ Object
Returns a string containing the rel values whose conditions are neighter false nor nil, or returns nil if no rel values remains.
Examples
{ :nofollow => true, :other => false, :me => true }.to_rel_attr
# => "nofollow me"
{ :foo => false, :bar => false }.to_rel_attr
# => nil
32 33 34 35 36 37 |
# File 'lib/html_attributes/hash.rb', line 32 def to_rel_attr self.select { |klass, condition| condition }. # remove rel values with nil or false condition map { |elem| elem.first.to_s }. # throw condition away sort. # sort alphabetically to_rel_attr # join with ' ' or return nil if empty end |