Class: ODDB::Text::Paragraph
- Includes:
- OddbUri
- Defined in:
- lib/oddb/export/yaml.rb,
lib/oddb/text/paragraph.rb
Constant Summary
Constants included from OddbUri
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.
- #set_format(*args) ⇒ Object
- #to_yaml_properties ⇒ Object
Methods included from OddbUri
#to_yaml, #to_yaml_map, #to_yaml_type
Methods inherited from String
Constructor Details
#initialize(str = '') ⇒ Paragraph
Returns a new instance of Paragraph.
13 14 15 16 17 18 |
# File 'lib/oddb/text/paragraph.rb', line 13 def initialize(str='') @formats = [] @text = u(str.dup) set_format() super(@text) 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
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/oddb/text/paragraph.rb', line 38 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 |
#set_format(*args) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/oddb/text/paragraph.rb', line 19 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_yaml_properties ⇒ Object
126 127 128 |
# File 'lib/oddb/export/yaml.rb', line 126 def to_yaml_properties [ '@text', '@formats' ] end |