Created
September 21, 2017 02:24
-
-
Save Ji-Yuhang/210253c7cc7033be28984ee5483bbba4 to your computer and use it in GitHub Desktop.
grape custom format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Grape::Entity.format_with :utc do |date| | |
date.strftime('%Y年%m月%d日 %H:%M') if date | |
end | |
Grape::Entity.format_with :date do |date| | |
date.strftime('%Y年%m月%d日') if date | |
end | |
Grape::Entity.format_with :datetime do |date| | |
date.strftime('%Y年%m月%d日 %H:%M:%S') if date | |
end | |
Grape::Entity.format_with :rmb do |money, options| | |
ActiveSupport::NumberHelper.number_to_currency(money, unit: '元') if money | |
end | |
Grape::Entity.format_with :rmb_p0 do |money, options| | |
ActiveSupport::NumberHelper.number_to_currency(money, unit: '元', precision: 0) if money | |
end | |
Grape::Entity.format_with :round do |money| | |
ActiveSupport::NumberHelper.number_to_rounded(money, precision: 2).to_f if money | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment