Class: Uniword::Shading

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/uniword/shading.rb

Overview

Represents shading/background pattern for text or paragraphs

Shading provides background colors and patterns for text runs or paragraph backgrounds.

Examples:

Solid background

shading = Shading.new(type: 'clear', fill: 'FFFF00')

Pattern background

shading = Shading.new(
  type: 'diagStripe',
  color: '0000FF',
  fill: 'FFFF00'
)

Constant Summary collapse

TYPES =

Shading pattern types

%w[
  clear solid horzStripe vertStripe
  reverseDiagStripe diagStripe horzCross
  diagCross thinHorzStripe thinVertStripe
  thinReverseDiagStripe thinDiagStripe
  thinHorzCross thinDiagCross
  pct5 pct10 pct12 pct15 pct20 pct25
  pct30 pct35 pct37 pct40 pct45 pct50
  pct55 pct60 pct62 pct65 pct70 pct75
  pct80 pct85 pct87 pct90 pct95
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**attributes) ⇒ Shading

Returns a new instance of Shading.



42
43
44
45
# File 'lib/uniword/shading.rb', line 42

def initialize(**attributes)
  super
  validate_type
end

Instance Attribute Details

#colorString

Foreground color (for patterns)

Returns:

  • (String)

    the current value of color



24
25
26
# File 'lib/uniword/shading.rb', line 24

def color
  @color
end

#fillString

Background fill color

Returns:

  • (String)

    the current value of fill



24
25
26
# File 'lib/uniword/shading.rb', line 24

def fill
  @fill
end

#typeString

Shading pattern type

Returns:

  • (String)

    the current value of type



24
25
26
# File 'lib/uniword/shading.rb', line 24

def type
  @type
end

Class Method Details

.diagonal_stripe(color: "000000", fill: "FFFFFF") ⇒ Shading

Create diagonal stripe pattern

Parameters:

  • color (String) (defaults to: "000000")

    Stripe color

  • fill (String) (defaults to: "FFFFFF")

    Background color

Returns:



88
89
90
# File 'lib/uniword/shading.rb', line 88

def self.diagonal_stripe(color: "000000", fill: "FFFFFF")
  new(type: "diagStripe", color: color, fill: fill)
end

.horizontal_stripe(color: "000000", fill: "FFFFFF") ⇒ Shading

Create horizontal stripe pattern

Parameters:

  • color (String) (defaults to: "000000")

    Stripe color

  • fill (String) (defaults to: "FFFFFF")

    Background color

Returns:



70
71
72
# File 'lib/uniword/shading.rb', line 70

def self.horizontal_stripe(color: "000000", fill: "FFFFFF")
  new(type: "horzStripe", color: color, fill: fill)
end

.pattern(type, color: "auto", fill: nil) ⇒ Shading

Create pattern shading

Parameters:

  • type (String)

    Pattern type

  • color (String) (defaults to: "auto")

    Foreground color

  • fill (String) (defaults to: nil)

    Background color

Returns:



61
62
63
# File 'lib/uniword/shading.rb', line 61

def self.pattern(type, color: "auto", fill: nil)
  new(type: type, color: color, fill: fill)
end

.reverse_diagonal_stripe(color: "000000", fill: "FFFFFF") ⇒ Shading

Create reverse diagonal stripe pattern

Parameters:

  • color (String) (defaults to: "000000")

    Stripe color

  • fill (String) (defaults to: "FFFFFF")

    Background color

Returns:



97
98
99
# File 'lib/uniword/shading.rb', line 97

def self.reverse_diagonal_stripe(color: "000000", fill: "FFFFFF")
  new(type: "reverseDiagStripe", color: color, fill: fill)
end

.solid(fill) ⇒ Shading

Create solid shading with fill color

Parameters:

  • fill (String)

    Fill color (hex)

Returns:



51
52
53
# File 'lib/uniword/shading.rb', line 51

def self.solid(fill)
  new(type: "clear", fill: fill)
end

.vertical_stripe(color: "000000", fill: "FFFFFF") ⇒ Shading

Create vertical stripe pattern

Parameters:

  • color (String) (defaults to: "000000")

    Stripe color

  • fill (String) (defaults to: "FFFFFF")

    Background color

Returns:



79
80
81
# File 'lib/uniword/shading.rb', line 79

def self.vertical_stripe(color: "000000", fill: "FFFFFF")
  new(type: "vertStripe", color: color, fill: fill)
end