Class: Super::Display::SchemaTypes::Badge

Inherits:
Object
  • Object
show all
Extended by:
Useful::Builder
Defined in:
lib/super/display/schema_types.rb

Instance Method Summary collapse

Methods included from Useful::Builder

builder, builder_with_block

Constructor Details

#initialize(builder) ⇒ Badge

Returns a new instance of Badge.



67
68
69
70
71
72
# File 'lib/super/display/schema_types.rb', line 67

def initialize(builder)
  @builder = builder
  @whens = {}
  format_for_lookup(&:itself)
  format_for_display(&:itself)
end

Instance Method Details

#buildObject



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/super/display/schema_types.rb', line 92

def build
  @builder.transform do |value|
    lookup_value = @format_for_lookup.call(value)
    block = @whens[lookup_value] || @else
    Super::Badge.new(
      @format_for_display.call(value),
      styles: block&.call
    )
  end
  @builder.build
end