Class: OoxmlParser::FontStyle
- Inherits:
-
Object
- Object
- OoxmlParser::FontStyle
- Defined in:
- lib/ooxml_parser/common_parser/common_data/font_style.rb
Instance Attribute Summary collapse
-
#bold ⇒ false, true
Is bold?.
-
#italic ⇒ false, true
Is bold?.
-
#strike ⇒ Strike
Strike type.
-
#underlined ⇒ Underline
Underline type.
Class Method Summary collapse
-
.generate_all_styles ⇒ Array
Generate all possible combination of styles (16).
-
.generate_all_styles_without_stroke ⇒ Array
Generate all possible combination of styles without parameter stoke (8).
Instance Method Summary collapse
-
#+(other) ⇒ FontStyle
Default + operator.
-
#==(other) ⇒ true, false
Default == operator.
- #copy ⇒ Object
-
#initialize(bold = false, italic = false, underlined = Underline.new(:none), strike = :none) ⇒ FontStyle
constructor
Default constructor.
-
#to_s ⇒ String
Default to_s operator.
Constructor Details
#initialize(bold = false, italic = false, underlined = Underline.new(:none), strike = :none) ⇒ FontStyle
Default constructor
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
#bold ⇒ false, true
Returns is bold?.
8 9 10 |
# File 'lib/ooxml_parser/common_parser/common_data/font_style.rb', line 8 def bold @bold end |
#italic ⇒ false, true
Returns is bold?.
10 11 12 |
# File 'lib/ooxml_parser/common_parser/common_data/font_style.rb', line 10 def italic @italic end |
#strike ⇒ Strike
Returns strike type.
14 15 16 |
# File 'lib/ooxml_parser/common_parser/common_data/font_style.rb', line 14 def strike @strike end |
#underlined ⇒ Underline
Returns underline type.
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_styles ⇒ Array
Generate all possible combination of styles (16)
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_stroke ⇒ Array
Generate all possible combination of styles without parameter stoke (8)
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
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
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 |
#copy ⇒ Object
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_s ⇒ String
Default to_s operator
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 |