Sha256: a82169d056348cc53ca2778cb175a53e98ce6779ee7ec568164e1527a5e71522

Contents?: true

Size: 928 Bytes

Versions: 64

Compression:

Stored size: 928 Bytes

Contents

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

module FeduxOrgStdlib
  module LogicConverters
    class YNConverter

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

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
fedux_org-stdlib-0.6.29 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.6.28 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.6.27 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.6.26 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.6.25 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.6.23 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.6.22 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.6.21 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.6.20 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.6.18 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.6.17 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.6.16 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.6.15 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.6.14 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.6.13 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.6.12 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.6.11 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.6.9 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.6.8 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.6.7 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb