Class: Uniword::Resource::ThemeProcessor

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hue_shift: nil, saturation_shift: nil, lightness_shift: nil) ⇒ ThemeProcessor

Create processor with optional shift values

Parameters:

  • hue_shift (Integer, nil) (defaults to: nil)

    Hue shift in degrees (random if nil)

  • saturation_shift (Integer, nil) (defaults to: nil)

    Saturation shift percent (random if nil)

  • lightness_shift (Integer, nil) (defaults to: nil)

    Lightness shift percent (random if nil)



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_shiftObject (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_shiftObject (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_shiftObject (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

Parameters:

  • seed (String)

    Seed string for deterministic shift generation

Returns:



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

.identityThemeProcessor

Create identity processor (no transformations)

Returns:



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)

Returns:

  • (Boolean)

    true if all shifts are zero



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

Parameters:

Returns:

  • (Drawingml::Theme)

    Processed theme with shifted colors and substituted fonts



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