Sha256: 4b705b552cb3af5117983177b8ece035cf23d241706c334491b17f72080b5e16

Contents?: true

Size: 1.2 KB

Versions: 11

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", "no" or empty string (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_FALSE.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

11 entries across 11 versions & 2 rubygems

Version Path
ruby-graphviz-1.2.5 lib/graphviz/types/gv_bool.rb
ruby-graphviz-1.2.4 lib/graphviz/types/gv_bool.rb
ruby-graphviz-1.2.3 lib/graphviz/types/gv_bool.rb
ruby-graphviz-1.2.2 lib/graphviz/types/gv_bool.rb
ruby-graphviz-1.2.1 lib/graphviz/types/gv_bool.rb
ruby-graphviz-1.2.0 lib/graphviz/types/gv_bool.rb
ruby-graphviz-1.1.0 lib/graphviz/types/gv_bool.rb
ruby-graphviz_c-1.1.1 lib/graphviz/types/gv_bool.rb
ruby-graphviz_c-1.1.0 lib/graphviz/types/gv_bool.rb
ruby-graphviz-1.0.9 lib/graphviz/types/gv_bool.rb
ruby-graphviz-1.0.8 lib/graphviz/types/gv_bool.rb