Sha256: 47ef576ce33092afea42a4d48ae2e6e7aace8d41782cf611a20df31492c4a11b

Contents?: true

Size: 999 Bytes

Versions: 56

Compression:

Stored size: 999 Bytes

Contents

# encoding: utf-8
require 'fedux_org_stdlib/logic_converters/exceptions'

module FeduxOrgStdlib
  module LogicConverters
    # Convert 'true'/'false' to true/false
    class TrueFalseConverter
      # @param [true,false] value
      #   the logic value which should be converted
      # @return [String]
      #   the converted value: true => 'true', false => 'false', '' => nil
      #
      # @example Parse true
      #    converter = FeduxOrgStdlib::LogicConverters::OnOffConverter.new
      #    converter.parse( true ) # 'true'
      #
      # @example Parse false
      #    converter = FeduxOrgStdlib::LogicConverters::OnOffConverter.new
      #    converter.parse( false ) # 'false'
      def parse(value)
        case value
        when true
          'true'
        when false
          'false'
        when ''
          nil
        else
          fail FeduxOrgStdlib::LogicConverters::Exceptions::InvalidValue, "Unknown logic value \"#{value}\"."
        end
      end
    end
  end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
fedux_org-stdlib-0.8.6 lib/fedux_org_stdlib/logic_converters/true_false_converter.rb
fedux_org-stdlib-0.8.5 lib/fedux_org_stdlib/logic_converters/true_false_converter.rb
fedux_org-stdlib-0.8.4 lib/fedux_org_stdlib/logic_converters/true_false_converter.rb
fedux_org-stdlib-0.8.3 lib/fedux_org_stdlib/logic_converters/true_false_converter.rb
fedux_org-stdlib-0.8.0 lib/fedux_org_stdlib/logic_converters/true_false_converter.rb
fedux_org-stdlib-0.7.33 lib/fedux_org_stdlib/logic_converters/true_false_converter.rb
fedux_org-stdlib-0.7.31 lib/fedux_org_stdlib/logic_converters/true_false_converter.rb
fedux_org-stdlib-0.7.30 lib/fedux_org_stdlib/logic_converters/true_false_converter.rb
fedux_org-stdlib-0.7.29 lib/fedux_org_stdlib/logic_converters/true_false_converter.rb
fedux_org-stdlib-0.7.28 lib/fedux_org_stdlib/logic_converters/true_false_converter.rb
fedux_org-stdlib-0.7.27 lib/fedux_org_stdlib/logic_converters/true_false_converter.rb
fedux_org-stdlib-0.7.26 lib/fedux_org_stdlib/logic_converters/true_false_converter.rb
fedux_org-stdlib-0.7.25 lib/fedux_org_stdlib/logic_converters/true_false_converter.rb
fedux_org-stdlib-0.7.24 lib/fedux_org_stdlib/logic_converters/true_false_converter.rb
fedux_org-stdlib-0.7.23 lib/fedux_org_stdlib/logic_converters/true_false_converter.rb
fedux_org-stdlib-0.7.22 lib/fedux_org_stdlib/logic_converters/true_false_converter.rb