Sha256: 359b6fa7fba599fe1887613d1111506c89b8f1b4bbcbcce3edaeaec6c9c99d29

Contents?: true

Size: 885 Bytes

Versions: 62

Compression:

Stored size: 885 Bytes

Contents

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

            def process
              @parsers.define_attribute(:date) do |parser|
                parser.def_parser  do |value|
                  value.is_a?(Array) ? value.map { |v| parse_date(v) } :  parse_date(value)
                end.def_serializer do |value|
                  value.is_a?(Array) ? value.map { |d| d && d.strftime('%Y-%m-%d') } : value && value.strftime('%Y-%m-%d')
                end
              end
            end

            private

            def parse_date(value)
              begin
                (value.to_s.empty?) ? nil : Time.parse(value)
              rescue
                nil
              end
            end

          end
        end
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
eco-helpers-1.3.12 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-1.3.11 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-1.3.10 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-1.3.9 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-1.3.8 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-1.3.7 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-1.3.6 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-1.3.5 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-1.3.4 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-1.3.3 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-1.3.2 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-1.3.1 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-1.2.2 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-1.2.1 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-1.1.8 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-1.1.7 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-1.1.6 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-1.1.5 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-1.1.4 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-1.1.3 lib/eco/api/common/people/default_parsers/date_parser.rb