Sha256: 57be1c618c5be670a72d5d31f4d3c89f326cbbe968daae8b27b33afd95a9af7a

Contents?: true

Size: 1.2 KB

Versions: 3

Compression:

Stored size: 1.2 KB

Contents

class BoolException < RuntimeError
end

# bool
#
# For the bool type, 
# - TRUE values are represented by "true" or "yes" (case-insensitive), true and any non-zero integer
# - FALSE values by "false" or "no" (case-insensitive), false and zero.
#
# Example 
#
#   graph[:center] = "true"
# or
#   graph[:center] = true
# or
#   graph[:center] = 23
class GraphViz
   class Types
      class GvBool < Common
         BOOL_TRUE = ["true", "yes"]
         BOOL_FALSE = ["false", "no"]

         def check(data)
            if true == data or (data.is_a?(Integer) and data != 0) or (data.is_a?(String) and BOOL_TRUE.include?(data.downcase))
               @to_ruby = true
               return data
            end
            
            if false == data or (data.is_a?(Integer) and data == 0) or (data.is_a?(String) and BOOL_FALSE.include?(data.downcase))
               @to_ruby = false
               return data
            end

            raise BoolException, "Invalid bool value"
         end

         def output
            return @data.to_s.inspect.gsub( "\\\\", "\\" )
         end

         alias :to_gv :output
         alias :to_s :output

         def to_ruby
            @to_ruby
         end
      end
   end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruby-graphviz-1.0.3 lib/graphviz/types/gv_bool.rb
ruby-graphviz-1.0.2 lib/graphviz/types/gv_bool.rb
ruby-graphviz-1.0.1 lib/graphviz/types/gv_bool.rb