Class: EBPS::Text::Paragraph

Inherits:
Object
  • Object
show all
Defined in:
lib/ebps/text/paragraph.rb

Direct Known Subclasses

Cell, LinkedParagraph, Subheading

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str = '') ⇒ Paragraph

Returns a new instance of Paragraph.



11
12
13
14
15
16
# File 'lib/ebps/text/paragraph.rb', line 11

def initialize(str='')
  @formats = []
  @text = ''
				set_format()
  self << str
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object



17
18
19
# File 'lib/ebps/text/paragraph.rb', line 17

def method_missing *args, &block
  @text.send *args, &block
end

Instance Attribute Details

#alignObject

Returns the value of attribute align.



10
11
12
# File 'lib/ebps/text/paragraph.rb', line 10

def align
  @align
end

#formatsObject (readonly)

Returns the value of attribute formats.



9
10
11
# File 'lib/ebps/text/paragraph.rb', line 9

def formats
  @formats
end

#textObject (readonly)

Returns the value of attribute text.



9
10
11
# File 'lib/ebps/text/paragraph.rb', line 9

def text
  @text
end

Instance Method Details

#<<(str) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ebps/text/paragraph.rb', line 42

def <<(str)
  if(str.is_a? Paragraph)
    @align = str.align
    txt = str.text
    str.formats.each { |fmt|
      set_format(*fmt.values)
      @text << txt[fmt.range]
    }
  else
    @text << str.to_s
  end
  self
end

#set_format(*args) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ebps/text/paragraph.rb', line 20

def set_format(*args)
  if(fmt = @formats.last)
    return if(fmt == args)
    if(fmt.start == @text.length)
      @formats.pop
      fmt = @formats.last
      if(fmt == args)
        fmt.end = -1
        return
      end
    else
      fmt.end	= (@text.length - 1)
    end
  end
  fmt = Text::Format.new(*args)
  fmt.start = (@text.length)
  @formats.push(fmt)
  fmt
end

#to_sObject



39
40
41
# File 'lib/ebps/text/paragraph.rb', line 39

def to_s
  @text.dup
end