Class: RailsLens::ERD::DomainColorMapper
- Inherits:
-
Object
- Object
- RailsLens::ERD::DomainColorMapper
- Defined in:
- lib/rails_lens/erd/domain_color_mapper.rb
Overview
Assigns a consistent color to a domain from a predefined palette.
Constant Summary collapse
- DEFAULT_COLORS =
Default color palette for domains using CSS named colors.
%w[ lightblue lightcoral lightgreen lightyellow plum lightcyan lightgray ].freeze
- FALLBACK_COLOR =
The color used for domains not found in the initial list.
'lightgray'
Instance Method Summary collapse
-
#color_for(domain) ⇒ String
Returns the color for a given domain.
-
#initialize(domains, colors: DEFAULT_COLORS) ⇒ DomainColorMapper
constructor
A new instance of DomainColorMapper.
Constructor Details
#initialize(domains, colors: DEFAULT_COLORS) ⇒ DomainColorMapper
Returns a new instance of DomainColorMapper.
23 24 25 26 |
# File 'lib/rails_lens/erd/domain_color_mapper.rb', line 23 def initialize(domains, colors: DEFAULT_COLORS) @colors = colors.empty? ? [FALLBACK_COLOR] : colors @domain_map = domains.uniq.each_with_index.to_h end |
Instance Method Details
#color_for(domain) ⇒ String
Returns the color for a given domain.
32 33 34 35 36 37 |
# File 'lib/rails_lens/erd/domain_color_mapper.rb', line 32 def color_for(domain) domain_index = @domain_map[domain] return FALLBACK_COLOR unless domain_index @colors[domain_index % @colors.length] end |