Sha256: 515e13c12ea5db4637dfda984543516f3418f6035e28abf82ee061f8067b2966

Contents?: true

Size: 950 Bytes

Versions: 64

Compression:

Stored size: 950 Bytes

Contents

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

module FeduxOrgStdlib
  module LogicConverters
    class YesNoConverter
      # @param [true,false] value
      #   the logic value which should be converted
      # @return [String]
      #   the converted value: true => yes, false => no, '' => nil
      #
      # @example Parse true
      #    converter = FeduxOrgStdlib::LogicConverters::OnOffConverter.new
      #    converter.parse( true ) # 'yes'
      #
      # @example Parse false
      #    converter = FeduxOrgStdlib::LogicConverters::OnOffConverter.new
      #    converter.parse( false ) # 'no'
      #   
      def parse( value )
        case value
        when true
          'yes'
        when false
          'no'
        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.6 lib/fedux_org_stdlib/logic_converters/yes_no_converter.rb
fedux_org-stdlib-0.6.5 lib/fedux_org_stdlib/logic_converters/yes_no_converter.rb
fedux_org-stdlib-0.6.4 lib/fedux_org_stdlib/logic_converters/yes_no_converter.rb
fedux_org-stdlib-0.6.3 lib/fedux_org_stdlib/logic_converters/yes_no_converter.rb