Sha256: 3bf3eb1b75cd8d97ab035e68b5e33f4b86275a77589286b87fa5c0c1b55b08c2

Contents?: true

Size: 956 Bytes

Versions: 56

Compression:

Stored size: 956 Bytes

Contents

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

module FeduxOrgStdlib
  module LogicConverters
    # Convert y/n to true/false
    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
          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.11.18 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.11.17 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.11.16 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.11.15 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.11.14 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.11.12 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.11.11 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.11.9 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.11.8 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.11.7 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.11.6 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.11.5 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.11.4 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.11.3 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.11.2 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.11.1 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.11.0 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.10.9 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.10.8 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb
fedux_org-stdlib-0.10.7 lib/fedux_org_stdlib/logic_converters/y_n_converter.rb