Sha256: b997b67b362f2b9b0ed9484c063073b493f293008840e0071c5e24e25133c41f

Contents?: true

Size: 672 Bytes

Versions: 93

Compression:

Stored size: 672 Bytes

Contents

class Eco::API::Common::People::DefaultParsers::DateParser < Eco::API::Common::Loaders::Parser
  attribute :date

  def parser(value, deps)
    value.is_a?(Array) ? value.map { |v| parse_date(v) } : parse_date(value)
  end

  def serializer(value, deps)
    value.is_a?(Array) ? value.map { |d| serialize_date(d) } : serialize_date(value)
  end

  private

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

  def serialize_date(value)
    return value if value.is_a?(String)
    begin
      value && value.strftime('%Y-%m-%d')
    rescue
      nil
    end
  end


end

Version data entries

93 entries across 93 versions & 1 rubygems

Version Path
eco-helpers-2.0.50 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.0.49 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.0.48 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.0.47 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.0.46 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.0.45 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.0.44 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.0.43 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.0.42 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.0.41 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.0.40 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.0.39 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.0.38 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.0.37 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.0.36 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.0.35 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.0.34 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.0.33 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.0.32 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.0.31 lib/eco/api/common/people/default_parsers/date_parser.rb