Permalink
Browse files

Simplified boolean logic

  • Loading branch information...
1 parent 672d8fc commit 1b9d1e37f4c147724e24c16a551a40e4338e51db @markus1189 markus1189 committed Jul 3, 2012
Showing with 16 additions and 21 deletions.
  1. +3 −3 bin/ruby2gv
  2. +5 −5 lib/graphviz.rb
  3. +3 −8 lib/graphviz/attrs.rb
  4. +2 −2 lib/graphviz/edge.rb
  5. +3 −3 lib/graphviz/xml.rb
View
@@ -106,7 +106,7 @@ class Rb2Gv
def parseFile( xFile, xFromFile = nil, xLib = nil )
- if xFromFile.nil? == false
+ if xFromFile
puts "Parse #{xFile} required in #{xFromFile} :" if DEBUG
else
puts "Parse #{xFile} :" if DEBUG
@@ -120,11 +120,11 @@ class Rb2Gv
if lxLineMatch = REQUIRE.match( xLine )
xRequiredLib = lxLineMatch[2].gsub( /\.(rb|so)$/, "" )
- if @hxNodes.has_key?( xRequiredLib ) == false
+ if not @hxNodes.has_key?( xRequiredLib )
puts " + Node #{xRequiredLib}" if DEBUG
xRequiredFile = getLibraryPath( xRequiredLib )
- if xRequiredFile.nil? == false
+ if xRequiredFile
unless @lxStops.include?(xRequiredLib)
@hxNodes[xRequiredLib] = gv_newNode( xRequiredLib )
parseFile( xRequiredFile, xFile, xRequiredLib )
View
@@ -131,7 +131,7 @@ def add_nodes(node_name, options = {})
def get_node( xNodeName, &block )
node = @hoNodes[xNodeName] || nil
- yield( node ) if( block and node.nil? == false )
+ yield( node ) if( block and node )
return node
end
@@ -298,7 +298,7 @@ def add_graph( xGraphName = nil, hOpts = {}, &block )
def get_graph( xGraphName, &block )
graph = @hoGraphs[xGraphName] || nil
- yield( graph ) if( block and graph.nil? == false )
+ yield( graph ) if( block and graph )
return graph
end
@@ -499,7 +499,7 @@ def output( hOpts = {} )
end
xDOTScript << "}"
- if @oParentGraph.nil? == false
+ if @oParentGraph
xDOTScript = "subgraph #{GraphViz.escape(@name, :unquote_empty => true)} {\n" << xDOTScript
return( xDOTScript )
@@ -776,7 +776,7 @@ def self.options( hOpts )
#
def self.parse( xFile, hOpts = {}, &block )
graph = Dot2Ruby::new( hOpts[:path], nil, nil ).eval( xFile )
- yield( graph ) if( block and graph.nil? == false )
+ yield( graph ) if( block and graph )
return graph
end
@@ -790,7 +790,7 @@ def self.parse( xFile, hOpts = {}, &block )
#
def self.parse_string( str, hOpts = {}, &block )
graph = Dot2Ruby::new( hOpts[:path], nil, nil ).eval_string( str )
- yield( graph ) if( block and graph.nil? == false )
+ yield( graph ) if( block and graph )
return graph
end
View
@@ -44,9 +44,6 @@ def []( key )
self[k] = v
end
else
- if @data.key?( key.to_s ) == false
- nil
- end
@data[key.to_s]
end
end
@@ -66,12 +63,10 @@ def []=( key, value )
rescue => e
raise AttributeException, "Invalide value `#{value}` for attribute `#{key}` : #{e}"
end
- unless value.nil?
- @data[key.to_s] = value
- if @graphviz.nil? == false
- @graphviz.set_position( @name, key.to_s, @data[key.to_s] )
- end
+ if value
+ @data[key.to_s] = value
+ @graphviz.set_position( @name, key.to_s, @data[key.to_s] ) if @graphviz
end
end
end
View
@@ -45,7 +45,7 @@ def initialize( vNodeOne, vNodeTwo, parent_graph )
# Return the node one as string (so with port if any)
def node_one( with_port = true )
- if @node_one_port.nil? or with_port == false
+ if not (@node_one_port and with_port)
GraphViz.escape(@node_one_id)
else
GraphViz.escape(@node_one_id, :force => true) + ":#{@node_one_port}"
@@ -55,7 +55,7 @@ def node_one( with_port = true )
# Return the node two as string (so with port if any)
def node_two( with_port = true )
- if @node_two_port.nil? or with_port == false
+ if not (@node_two_port and with_port)
GraphViz.escape(@node_two_id)
else
GraphViz.escape(@node_two_id, :force => true) + ":#{@node_two_port}"
View
@@ -49,7 +49,7 @@ def initialize( xml_file, *options )
@show_text = true
@show_attributes = true
- if options.nil? == false and options[0].nil? == false
+ if options and options[0]
options[0].each do |xKey, xValue|
case xKey.to_s
when "text"
@@ -74,11 +74,11 @@ def parse_xml_node( xml_node ) #:nodoc:
label = xml_node.name
if xml_node.has_attributes? and @show_attributes
label = "{ " + xml_node.name
-
+
xml_node.attributes.each do |xName, xValue|
label << "| { #{xName} | #{xValue} } "
end
-
+
label << "}"
end
@graph.add_nodes( local_node_name, "label" => label, "color" => "blue", "shape" => "record" )

0 comments on commit 1b9d1e3

Please sign in to comment.