Class: Sablon::HTMLConverter::TextFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/sablon/html/ast.rb

Class Method Summary collapse

Instance Method Summary collapse

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

.defaultObject



128
129
130
# File 'lib/sablon/html/ast.rb', line 128

def self.default
  @default ||= new(false, false, false)
end

Instance Method Details

#inspectObject



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_docxObject



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_boldObject



132
133
134
# File 'lib/sablon/html/ast.rb', line 132

def with_bold
  TextFormat.new(true, @italic, @underline)
end

#with_italicObject



136
137
138
# File 'lib/sablon/html/ast.rb', line 136

def with_italic
  TextFormat.new(@bold, true, @underline)
end

#with_underlineObject



140
141
142
# File 'lib/sablon/html/ast.rb', line 140

def with_underline
  TextFormat.new(@bold, @italic, true)
end