module Swa::DataPresentation
Constants
- WIDTH_BY_TYPE
Protected Instance Methods
camelize(symbol)
click to toggle source
# File lib/swa/data_presentation.rb, line 56 def camelize(symbol) symbol.to_s.split("_").map(&:capitalize).join("") end
camelize_keys(data)
click to toggle source
# File lib/swa/data_presentation.rb, line 45 def camelize_keys(data) case data when Hash data.map { |k,v| [camelize(k), camelize_keys(v)] }.to_h when Array data.map { |v| camelize_keys(v) } else data end end
field(resource, field_name, type = field_name)
click to toggle source
# File lib/swa/data_presentation.rb, line 39 def field(resource, field_name, type = field_name) width = WIDTH_BY_TYPE.fetch(type.to_sym) value = resource.public_send(field_name) pad(value, width) end
pad(s, width)
click to toggle source
# File lib/swa/data_presentation.rb, line 13 def pad(s, width) s = (s || "").to_s s.ljust(width) end
quoted(value)
click to toggle source
# File lib/swa/data_presentation.rb, line 9 def quoted(value) %("#{value}") if value && !value.empty? end
rpad(s, width)
click to toggle source
# File lib/swa/data_presentation.rb, line 18 def rpad(s, width) s = (s || "").to_s s.rjust(width) end