# 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