Class: Hash

Inherits:
Object show all
Defined in:
lib/graphviz/core_ext.rb

Overview

Instance Method Summary collapse

Instance Method Details

#each_except(e, &b) ⇒ Object

x =

:none => String,
:png => "file.png",
:svg => "file.svg"

x.each_except( :key => [:none], :value => [/.png$/] ) do |k, v|

puts "#{k} -> #{v}"

end

> svg -> file.svg



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/graphviz/core_ext.rb', line 46

def each_except( e, &b )
   key_table = (e[:key]||[]).clone.delete_if {|i| i.kind_of? Regexp }
   key_regexp = (e[:key]||[]).clone.delete_if {|i| key_table.include? i }.map {|i| i.to_s }.join("|")

   value_table = (e[:value]||[]).clone.delete_if {|i| i.kind_of? Regexp }
   value_regexp = (e[:value]||[]).clone.delete_if {|i| value_table.include? i }.map {|i| i.to_s }.join("|")

   self.each do |k, v|
      yield( k, v ) unless (key_table.size > 0 and key_table.include?(k)) or (key_regexp.size > 0 and k.to_s.match(key_regexp)) or (value_table.size > 0 and value_table.include?(v)) or (value_regexp.size > 0 and v.to_s.match(value_regexp))
   end
end

#symbolize_keysObject



28
29
30
31
32
33
# File 'lib/graphviz/core_ext.rb', line 28

def symbolize_keys
   inject({}) do |options, (key, value)|
      options[(key.to_sym rescue key) || key] = value
   options
   end
end