ministryofjustice/Claim-for-Crown-Court-Defence

View on GitHub
app/interfaces/api/helpers/formatters.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
92%
module API
  module Helpers
    module Formatters
      extend Grape::API::Helpers

      Grape::Entity.format_with :utc do |date|
        unless date.nil?
          date.is_a?(Time) ? date.utc : date.strftime('%Y-%m-%d')
        end
      end

      Grape::Entity.format_with(:string, &:to_s)

      Grape::Entity.format_with :decimal do |number|
        number.to_f.round(2)
      end

      Grape::Entity.format_with :integer_string do |number|
        number.to_i.to_s
      end

      Grape::Entity.format_with :bool_char do |boolean|
        boolean.to_s.true? ? 'Y' : 'N'
      end
    end
  end
end