Class: ODDB::Text::Paragraph
- Inherits:
-
Object
- Object
- ODDB::Text::Paragraph
- Defined in:
- lib/oddb/text/paragraph.rb
Instance Attribute Summary collapse
-
#align ⇒ Object
Returns the value of attribute align.
-
#formats ⇒ Object
readonly
Returns the value of attribute formats.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #<<(str) ⇒ Object
-
#initialize(str = '') ⇒ Paragraph
constructor
A new instance of Paragraph.
- #method_missing(*args, &block) ⇒ Object
- #preformatted? ⇒ Boolean
- #set_format(*args) ⇒ Object
Constructor Details
#initialize(str = '') ⇒ Paragraph
Returns a new instance of Paragraph.
13 14 15 16 17 |
# File 'lib/oddb/text/paragraph.rb', line 13 def initialize(str='') @formats = [] @text = u(str.dup) set_format() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, &block) ⇒ Object
18 19 20 |
# File 'lib/oddb/text/paragraph.rb', line 18 def method_missing *args, &block @text.send *args, &block end |
Instance Attribute Details
#align ⇒ Object
Returns the value of attribute align.
12 13 14 |
# File 'lib/oddb/text/paragraph.rb', line 12 def align @align end |
#formats ⇒ Object (readonly)
Returns the value of attribute formats.
11 12 13 |
# File 'lib/oddb/text/paragraph.rb', line 11 def formats @formats end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
11 12 13 |
# File 'lib/oddb/text/paragraph.rb', line 11 def text @text end |
Instance Method Details
#<<(str) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/oddb/text/paragraph.rb', line 43 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 end self end |
#preformatted? ⇒ Boolean
21 22 23 |
# File 'lib/oddb/text/paragraph.rb', line 21 def preformatted? @preformatted end |
#set_format(*args) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/oddb/text/paragraph.rb', line 24 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 |