Class: Sablon::HTMLConverter::TextFormat
- Inherits:
-
Object
- Object
- Sablon::HTMLConverter::TextFormat
- Defined in:
- lib/sablon/html/ast.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(bold, italic, underline) ⇒ TextFormat
constructor
A new instance of TextFormat.
- #inspect ⇒ Object
- #to_docx ⇒ Object
- #with_bold ⇒ Object
- #with_italic ⇒ Object
- #with_underline ⇒ Object
Constructor Details
#initialize(bold, italic, underline) ⇒ TextFormat
Returns a new instance of TextFormat.
102 103 104 105 106 |
# File 'lib/sablon/html/ast.rb', line 102 def initialize(bold, italic, underline) @bold = bold @italic = italic @underline = underline end |
Class Method Details
.default ⇒ Object
128 129 130 |
# File 'lib/sablon/html/ast.rb', line 128 def self.default @default ||= new(false, false, false) end |
Instance Method Details
#inspect ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/sablon/html/ast.rb', line 108 def inspect parts = [] parts << 'bold' if @bold parts << 'italic' if @italic parts << 'underline' if @underline parts.join('|') end |
#to_docx ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/sablon/html/ast.rb', line 116 def to_docx styles = [] styles << '<w:b />' if @bold styles << '<w:i />' if @italic styles << '<w:u w:val="single"/>' if @underline if styles.any? "<w:rPr>#{styles.join}</w:rPr>" else '' end end |
#with_bold ⇒ Object
132 133 134 |
# File 'lib/sablon/html/ast.rb', line 132 def with_bold TextFormat.new(true, @italic, @underline) end |
#with_italic ⇒ Object
136 137 138 |
# File 'lib/sablon/html/ast.rb', line 136 def with_italic TextFormat.new(@bold, true, @underline) end |
#with_underline ⇒ Object
140 141 142 |
# File 'lib/sablon/html/ast.rb', line 140 def with_underline TextFormat.new(@bold, @italic, true) end |