Sha256: 0efcfcddb3ca4d5e5f5254dbc64d72568e40b1e31e50d0ec4514b16d90e84810

Contents?: true

Size: 700 Bytes

Versions: 51

Compression:

Stored size: 700 Bytes

Contents

module Eco
  module API
    module Common
      module People
        class DefaultParsers
          class BooleanParser < People::BaseParser

            def process
              @parsers.define_attribute(:boolean) do |parser|
                parser.def_parser  do |value|
                  value.is_a?(Array) ? value.map { |v| truthy(v) } : truthy(value)
                end.def_serializer do |value|
                  value.to_s
                end
              end
            end

            private

            def truthy (value)
              %w[true y yes x].include?(value.to_s&.downcase)
            end
          end
        end
      end
    end
  end
end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
eco-helpers-0.6.11 lib/eco/api/common/people/default_parsers/boolean_parser.rb
eco-helpers-0.6.9 lib/eco/api/common/people/default_parsers/boolean_parser.rb
eco-helpers-0.6.8 lib/eco/api/common/people/default_parsers/boolean_parser.rb
eco-helpers-0.6.7 lib/eco/api/common/people/default_parsers/boolean_parser.rb
eco-helpers-0.6.6 lib/eco/api/common/people/default_parsers/boolean_parser.rb
eco-helpers-0.6.5 lib/eco/api/common/people/default_parsers/boolean_parser.rb
eco-helpers-0.6.4 lib/eco/api/common/people/default_parsers/boolean_parser.rb
eco-helpers-0.6.3 lib/eco/api/common/people/default_parsers/boolean_parser.rb
eco-helpers-0.6.2 lib/eco/api/common/people/default_parsers/boolean_parser.rb
eco-helpers-0.6.1 lib/eco/api/common/people/default_parsers/boolean_parser.rb
eco-helpers-0.6.0 lib/eco/api/common/people/default_parsers/boolean_parser.rb