Class: LedgerSync::Serialization::Type::FormatDateType

Inherits:
Type::Value
  • Object
show all
Defined in:
lib/ledger_sync/serialization/type/format_date_type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Type::ValueMixin

#assert_valid, #cast, included, #valid?

Constructor Details

#initialize(args = {}) ⇒ FormatDateType

Returns a new instance of FormatDateType.



9
10
11
12
13
# File 'lib/ledger_sync/serialization/type/format_date_type.rb', line 9

def initialize(args = {})
  @format = args.fetch(:format)

  super()
end

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format.



7
8
9
# File 'lib/ledger_sync/serialization/type/format_date_type.rb', line 7

def format
  @format
end

Instance Method Details

#cast_value(args = {}) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/ledger_sync/serialization/type/format_date_type.rb', line 15

def cast_value(args = {})
  value = args.fetch(:value)

  return if value.nil?

  value.to_datetime.strftime(format)
end