Module: HakumiComponents::Table::EllipsisConfig::TooltipConfigBuilder

Extended by:
T::Sig
Defined in:
app/components/hakumi_components/table/ellipsis_config.rb

Class Method Summary collapse

Class Method Details

.build(input) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'app/components/hakumi_components/table/ellipsis_config.rb', line 103

def self.build(input)
  return nil if input.nil? || input == false
  return EllipsisConfig::TooltipConfig.new(title: nil, options: {}) if input == true
  return EllipsisConfig::TooltipConfig.new(title: input, options: {}) if input.is_a?(String)

  return nil unless input.is_a?(Hash)

  normalized = input.deep_symbolize_keys
  title = normalized.delete(:title)
  title = nil unless title.nil? || title.is_a?(String) || title.is_a?(Proc)
  options = T.let({}, InputHash)
  normalized.each do |key, value|
    next unless key.is_a?(Symbol)

    options[key] = value
  end
  EllipsisConfig::TooltipConfig.new(title: title, options: options)
end