Class: OoxmlParser::FontStyle

Inherits:
Object
  • Object
show all
Defined in:
lib/ooxml_parser/common_parser/common_data/font_style.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bold = false, italic = false, underlined = Underline.new(:none), strike = :none) ⇒ FontStyle

Default constructor

Parameters:

  • bold (true, false) (defaults to: false)

    is bold?

  • italic (true, false) (defaults to: false)

    is italic?

  • underlined (true, false, String) (defaults to: Underline.new(:none))

    if not false or nil - default Underline, else none

  • strike (Symbol) (defaults to: :none)

    string with strike type



22
23
24
25
26
27
# File 'lib/ooxml_parser/common_parser/common_data/font_style.rb', line 22

def initialize(bold = false, italic = false, underlined = Underline.new(:none), strike = :none)
  @bold = bold
  @italic = italic
  @underlined = (underlined == false || underlined.nil?) ? Underline.new(:none) : underlined
  @strike = strike
end

Instance Attribute Details

#boldfalse, true

Returns is bold?.

Returns:

  • (false, true)

    is bold?



8
9
10
# File 'lib/ooxml_parser/common_parser/common_data/font_style.rb', line 8

def bold
  @bold
end

#italicfalse, true

Returns is bold?.

Returns:

  • (false, true)

    is bold?



10
11
12
# File 'lib/ooxml_parser/common_parser/common_data/font_style.rb', line 10

def italic
  @italic
end

#strikeStrike

Returns strike type.

Returns:

  • (Strike)

    strike type



14
15
16
# File 'lib/ooxml_parser/common_parser/common_data/font_style.rb', line 14

def strike
  @strike
end

#underlinedUnderline

Returns underline type.

Returns:



12
13
14
# File 'lib/ooxml_parser/common_parser/common_data/font_style.rb', line 12

def underlined
  @underlined
end

Class Method Details

.generate_all_stylesArray

Generate all possible combination of styles (16)

Returns:

  • (Array)

    with all FontStyle



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ooxml_parser/common_parser/common_data/font_style.rb', line 47

def generate_all_styles
  styles_array = []
  styles_array << generate_all_styles_without_stroke

  styles_array << FontStyle.new(true, true, Underline.new(:single), :single)
  styles_array << FontStyle.new(true, true, nil, :single)
  styles_array << FontStyle.new(true, false, Underline.new(:single), :single)
  styles_array << FontStyle.new(false, true, Underline.new(:single), :single)

  styles_array << FontStyle.new(true, false, nil, :single)
  styles_array << FontStyle.new(false, false, Underline.new(:single), :single)
  styles_array << FontStyle.new(false, true, nil, :single)
  styles_array << FontStyle.new(false, false, nil, :single)
  styles_array.flatten
end

.generate_all_styles_without_strokeArray

Generate all possible combination of styles without parameter stoke (8)

Returns:

  • (Array)

    with all FontStyle



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ooxml_parser/common_parser/common_data/font_style.rb', line 32

def generate_all_styles_without_stroke
  styles_array = []
  styles_array << FontStyle.new(true, true, Underline.new(:single), :none)
  styles_array << FontStyle.new(true, true, nil, :none)
  styles_array << FontStyle.new(true, false, Underline.new(:single), :none)
  styles_array << FontStyle.new(true, false, nil, :none)

  styles_array << FontStyle.new(false, true, Underline.new(:single), :none)
  styles_array << FontStyle.new(false, true, nil, :none)
  styles_array << FontStyle.new(false, false, Underline.new(:single), :none)
  styles_array << FontStyle.new(false, false, nil, :none)
end

Instance Method Details

#+(other) ⇒ FontStyle

Default + operator

Returns:

  • (FontStyle)

    the result of overlapping of two styles



72
73
74
75
76
77
78
79
# File 'lib/ooxml_parser/common_parser/common_data/font_style.rb', line 72

def +(other)
  result = FontStyle.new
  result.bold = (other.bold == @bold) ? @bold : other.bold
  result.italic = (other.italic == @italic) ? @italic : other.italic
  result.underlined = (other.underlined == @underlined) ? @underlined : other.underlined
  result.strike = (other.strike == @strike) ? @strike : other.strike
  result
end

#==(other) ⇒ true, false

Default == operator

Returns:

  • (true, false)

    true if two same, false if different



66
67
68
# File 'lib/ooxml_parser/common_parser/common_data/font_style.rb', line 66

def ==(other)
  (@bold == other.bold) && (@italic == other.italic) && (@underlined == other.underlined) && (@strike == other.strike)
end

#copyObject



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/ooxml_parser/common_parser/common_data/font_style.rb', line 87

def copy
  return dup if underlined.nil?
  other = FontStyle.new
  instance_variables.each do |variable|
    case variable
    when @underlined
      other.instance_variable_set(variable, underlined.copy)
    else
      other.instance_variable_set(variable, instance_variable_get(variable))
    end
  end
  other
end

#to_sString

Default to_s operator

Returns:

  • (String)

    with text representation



83
84
85
# File 'lib/ooxml_parser/common_parser/common_data/font_style.rb', line 83

def to_s
  "Bold: #{@bold}, Italic: #{@italic}, Underlined: #{@underlined}, Strike: #{@strike}"
end