Class: DocxGenerator::DSL::Text

Inherits:
Object
  • Object
show all
Defined in:
lib/docx_generator/dsl/text.rb

Instance Method Summary collapse

Constructor Details

#initialize(text_fragment, options = {}) {|_self| ... } ⇒ Text

Returns a new instance of Text.

Yields:

  • (_self)

Yield Parameters:



4
5
6
7
8
# File 'lib/docx_generator/dsl/text.rb', line 4

def initialize(text_fragment, options = {}, &block)
  @text_fragment = text_fragment
  @options = options
  yield self if block
end

Instance Method Details

#bold(value) ⇒ Object



10
11
12
# File 'lib/docx_generator/dsl/text.rb', line 10

def bold(value)
  @options[:bold] = value
end

#generateObject



34
35
36
37
38
39
40
41
42
# File 'lib/docx_generator/dsl/text.rb', line 34

def generate
  options = generate_text_options
  text = Word::Text.new({}, [@text_fragment])
  if options
    Word::Run.new({}, [options, text])
  else
    Word::Run.new({}, [text])
  end
end

#italics(value) ⇒ Object



14
15
16
# File 'lib/docx_generator/dsl/text.rb', line 14

def italics(value)
  @options[:italics] = value
end

#size(value) ⇒ Object



22
23
24
# File 'lib/docx_generator/dsl/text.rb', line 22

def size(value)
  @options[:size] = value
end

#subscript(value) ⇒ Object



30
31
32
# File 'lib/docx_generator/dsl/text.rb', line 30

def subscript(value)
  @options[:subscript] = value
end

#superscript(value) ⇒ Object



26
27
28
# File 'lib/docx_generator/dsl/text.rb', line 26

def superscript(value)
  @options[:superscript] = value
end

#to_sObject



44
45
46
# File 'lib/docx_generator/dsl/text.rb', line 44

def to_s
  generate.to_s
end

#underline(value) ⇒ Object



18
19
20
# File 'lib/docx_generator/dsl/text.rb', line 18

def underline(value)
  @options[:underline] = value
end