Skip to content

Commit

Permalink
Simplified boolean logic
Browse files Browse the repository at this point in the history
  • Loading branch information
markus1189 committed Jul 3, 2012
1 parent 672d8fc commit 1b9d1e3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 21 deletions.
6 changes: 3 additions & 3 deletions bin/ruby2gv
Expand Up @@ -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
Expand All @@ -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 )
Expand Down
10 changes: 5 additions & 5 deletions lib/graphviz.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
11 changes: 3 additions & 8 deletions lib/graphviz/attrs.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/graphviz/edge.rb
Expand Up @@ -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}"
Expand All @@ -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}"
Expand Down
6 changes: 3 additions & 3 deletions lib/graphviz/xml.rb
Expand Up @@ -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"
Expand All @@ -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" )
Expand Down

0 comments on commit 1b9d1e3

Please sign in to comment.