module GemsBond::Helpers::FormattingHelper
Formatting helper
Constants
- MISSING
Public Instance Methods
human_date(date)
click to toggle source
Returns a date with a readable format @param date [Date] @return [String] @example
human_date(Date.new(2017, 11, 19)) #=> "2007-11-19" human_date(nil) #=> "-"
# File lib/gems_bond/helpers/formatting_helper.rb, line 17 def human_date(date) return MISSING if date.nil? date.strftime("%F") end
human_number(number)
click to toggle source
Returns a number with a readable format @param date [Integer] @return [String] @example
human_number(1_000_000) #=> "1 000 000" human_number(nil) #=> "-"
# File lib/gems_bond/helpers/formatting_helper.rb, line 29 def human_number(number) return MISSING if number.nil? number.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1 ") end
human_score(score)
click to toggle source
Returns score out of 100 @param date [Float] @return [String] @example
human_score(0.5) #=> "50" human_score(nil) #=> "-"
# File lib/gems_bond/helpers/formatting_helper.rb, line 41 def human_score(score) return MISSING if score.nil? (score * 100).round end