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.6.4 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.6.3 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.6.2 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.6.1 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.6.0 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.5.10 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.5.9 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.5.8 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.5.7 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.5.6 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.5.5 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.5.4 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.5.3 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.5.2 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.5.1 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.4.9 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.4.8 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.4.7 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.4.6 lib/eco/api/common/people/default_parsers/date_parser.rb
eco-helpers-2.4.5 lib/eco/api/common/people/default_parsers/date_parser.rb