Class: Uniword::Resource::ThemeProcessor
- Inherits:
-
Object
- Object
- Uniword::Resource::ThemeProcessor
- Defined in:
- lib/uniword/resource/theme_processor.rb
Overview
MODEL for processing themes into copyright-free variants Has state (shift values) and behavior (process)
Constant Summary collapse
- HUE_SHIFT_RANGE =
Shift ranges for random generation
(-10..10)
- SATURATION_SHIFT_RANGE =
(-5..5)
- LIGHTNESS_SHIFT_RANGE =
(-5..5)
Instance Attribute Summary collapse
-
#hue_shift ⇒ Object
readonly
Returns the value of attribute hue_shift.
-
#lightness_shift ⇒ Object
readonly
Returns the value of attribute lightness_shift.
-
#saturation_shift ⇒ Object
readonly
Returns the value of attribute saturation_shift.
Class Method Summary collapse
-
.from_seed(seed) ⇒ ThemeProcessor
Create deterministic processor from seed string.
-
.identity ⇒ ThemeProcessor
Create identity processor (no transformations).
Instance Method Summary collapse
-
#identity? ⇒ Boolean
Check if this processor is an identity (no-op).
-
#initialize(hue_shift: nil, saturation_shift: nil, lightness_shift: nil) ⇒ ThemeProcessor
constructor
Create processor with optional shift values.
-
#process(theme) ⇒ Drawingml::Theme
Process a theme into a copyright-free variant.
Constructor Details
#initialize(hue_shift: nil, saturation_shift: nil, lightness_shift: nil) ⇒ ThemeProcessor
Create processor with optional shift values
22 23 24 25 26 27 |
# File 'lib/uniword/resource/theme_processor.rb', line 22 def initialize(hue_shift: nil, saturation_shift: nil, lightness_shift: nil) @hue_shift = hue_shift || rand(HUE_SHIFT_RANGE) @saturation_shift = saturation_shift || rand(SATURATION_SHIFT_RANGE) @lightness_shift = lightness_shift || rand(LIGHTNESS_SHIFT_RANGE) end |
Instance Attribute Details
#hue_shift ⇒ Object (readonly)
Returns the value of attribute hue_shift.
10 11 12 |
# File 'lib/uniword/resource/theme_processor.rb', line 10 def hue_shift @hue_shift end |
#lightness_shift ⇒ Object (readonly)
Returns the value of attribute lightness_shift.
10 11 12 |
# File 'lib/uniword/resource/theme_processor.rb', line 10 def lightness_shift @lightness_shift end |
#saturation_shift ⇒ Object (readonly)
Returns the value of attribute saturation_shift.
10 11 12 |
# File 'lib/uniword/resource/theme_processor.rb', line 10 def saturation_shift @saturation_shift end |
Class Method Details
.from_seed(seed) ⇒ ThemeProcessor
Create deterministic processor from seed string
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/uniword/resource/theme_processor.rb', line 33 def self.from_seed(seed) hash = Digest::SHA256.hexdigest(seed) # Use first 24 hex chars (6 bytes each) for shift values hue_shift = (hash[0, 6].to_i(16) % 21) - 10 # -10..10 saturation_shift = (hash[6, 6].to_i(16) % 11) - 5 # -5..5 lightness_shift = (hash[12, 6].to_i(16) % 11) - 5 # -5..5 new( hue_shift: hue_shift, saturation_shift: saturation_shift, lightness_shift: lightness_shift, ) end |
.identity ⇒ ThemeProcessor
Create identity processor (no transformations)
51 52 53 |
# File 'lib/uniword/resource/theme_processor.rb', line 51 def self.identity new(hue_shift: 0, saturation_shift: 0, lightness_shift: 0) end |
Instance Method Details
#identity? ⇒ Boolean
Check if this processor is an identity (no-op)
58 59 60 |
# File 'lib/uniword/resource/theme_processor.rb', line 58 def identity? hue_shift.zero? && saturation_shift.zero? && lightness_shift.zero? end |
#process(theme) ⇒ Drawingml::Theme
Process a theme into a copyright-free variant
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/uniword/resource/theme_processor.rb', line 66 def process(theme) theme.dup.tap do |processed| # Transform color scheme transform_color_scheme(processed.theme_elements.clr_scheme) if processed.theme_elements&.clr_scheme # Transform font scheme FontSubstitutor.transform_font_scheme(processed.theme_elements.font_scheme) if processed.theme_elements&.font_scheme # Update name to indicate it's a Uniword variant processed.name = "#{theme.name} (Uniword)" end end |