Sha256: f991befd8376977c3bb9cc13b9bd9edfcb627da152cedb5d3dd278a1f9c5e461

Contents?: true

Size: 979 Bytes

Versions: 56

Compression:

Stored size: 979 Bytes

Contents

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

module FeduxOrgStdlib
  module LogicConverters
    # Convert yes/no to true/false
    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
          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.10.6 lib/fedux_org_stdlib/logic_converters/yes_no_converter.rb
fedux_org-stdlib-0.10.5 lib/fedux_org_stdlib/logic_converters/yes_no_converter.rb
fedux_org-stdlib-0.10.4 lib/fedux_org_stdlib/logic_converters/yes_no_converter.rb
fedux_org-stdlib-0.10.3 lib/fedux_org_stdlib/logic_converters/yes_no_converter.rb
fedux_org-stdlib-0.10.2 lib/fedux_org_stdlib/logic_converters/yes_no_converter.rb
fedux_org-stdlib-0.10.1 lib/fedux_org_stdlib/logic_converters/yes_no_converter.rb
fedux_org-stdlib-0.10.0 lib/fedux_org_stdlib/logic_converters/yes_no_converter.rb
fedux_org-stdlib-0.9.8 lib/fedux_org_stdlib/logic_converters/yes_no_converter.rb
fedux_org-stdlib-0.9.7 lib/fedux_org_stdlib/logic_converters/yes_no_converter.rb
fedux_org-stdlib-0.9.6 lib/fedux_org_stdlib/logic_converters/yes_no_converter.rb
fedux_org-stdlib-0.9.5 lib/fedux_org_stdlib/logic_converters/yes_no_converter.rb
fedux_org-stdlib-0.9.4 lib/fedux_org_stdlib/logic_converters/yes_no_converter.rb
fedux_org-stdlib-0.9.2 lib/fedux_org_stdlib/logic_converters/yes_no_converter.rb
fedux_org-stdlib-0.9.1 lib/fedux_org_stdlib/logic_converters/yes_no_converter.rb
fedux_org-stdlib-0.9.0 lib/fedux_org_stdlib/logic_converters/yes_no_converter.rb
fedux_org-stdlib-0.8.11 lib/fedux_org_stdlib/logic_converters/yes_no_converter.rb
fedux_org-stdlib-0.8.10 lib/fedux_org_stdlib/logic_converters/yes_no_converter.rb
fedux_org-stdlib-0.8.9 lib/fedux_org_stdlib/logic_converters/yes_no_converter.rb
fedux_org-stdlib-0.8.8 lib/fedux_org_stdlib/logic_converters/yes_no_converter.rb
fedux_org-stdlib-0.8.7 lib/fedux_org_stdlib/logic_converters/yes_no_converter.rb