Class: EdifactConverter::XML::Paragraph
- Inherits:
-
Object
- Object
- EdifactConverter::XML::Paragraph
- Defined in:
- lib/edifact_converter/xml/paragraph.rb
Defined Under Namespace
Constant Summary collapse
- MONOSPACE =
'F'
- PROPOTIONAL =
'P'
- CENTER =
'M'
- RIGHT =
'H'
- BOLD =
'F'
- UNDERLINE =
'U'
- ITALIC =
'K'
- NORMAL =
'Normal'
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#font ⇒ Object
Returns the value of attribute font.
-
#format ⇒ Object
Returns the value of attribute format.
Instance Method Summary collapse
- #add_break ⇒ Object
- #add_end_break(text_break) ⇒ Object
- #add_start_break(text_break) ⇒ Object
- #add_text(text) ⇒ Object
- #divide_text(value, &block) ⇒ Object
- #empty? ⇒ Boolean
- #empty_copy ⇒ Object
- #end_breaks? ⇒ Boolean
- #ftx_format ⇒ Object
-
#initialize ⇒ Paragraph
constructor
A new instance of Paragraph.
- #insert_split(text) ⇒ Object
- #remove_end_break ⇒ Object
- #remove_start_break ⇒ Object
- #start_breaks? ⇒ Boolean
- #texts? ⇒ Boolean
- #to_s ⇒ Object
- #to_subelms(next_paragraph) ⇒ Object
Constructor Details
#initialize ⇒ Paragraph
Returns a new instance of Paragraph.
29 30 31 32 |
# File 'lib/edifact_converter/xml/paragraph.rb', line 29 def initialize() self.font = PROPOTIONAL self.format = NORMAL end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
15 16 17 |
# File 'lib/edifact_converter/xml/paragraph.rb', line 15 def content @content end |
#font ⇒ Object
Returns the value of attribute font.
15 16 17 |
# File 'lib/edifact_converter/xml/paragraph.rb', line 15 def font @font end |
#format ⇒ Object
Returns the value of attribute format.
15 16 17 |
# File 'lib/edifact_converter/xml/paragraph.rb', line 15 def format @format end |
Instance Method Details
#add_break ⇒ Object
62 63 64 |
# File 'lib/edifact_converter/xml/paragraph.rb', line 62 def add_break content.push Break.new end |
#add_end_break(text_break) ⇒ Object
46 47 48 |
# File 'lib/edifact_converter/xml/paragraph.rb', line 46 def add_end_break(text_break) content.push text_break end |
#add_start_break(text_break) ⇒ Object
42 43 44 |
# File 'lib/edifact_converter/xml/paragraph.rb', line 42 def add_start_break(text_break) content.unshift text_break end |
#add_text(text) ⇒ Object
58 59 60 |
# File 'lib/edifact_converter/xml/paragraph.rb', line 58 def add_text(text) content.push Text.new(text) end |
#divide_text(value, &block) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/edifact_converter/xml/paragraph.rb', line 142 def divide_text(value, &block) chars = value.encode("iso-8859-1").chars text = StringIO.new text.set_encoding("iso-8859-1") chars = chars.reject do |c| if text.size == 69 and chars.count > 1 text.string = insert_split(text, &block) end text.seek text.size text.write c true end text.string.encode "UTF-8" end |
#empty? ⇒ Boolean
66 67 68 |
# File 'lib/edifact_converter/xml/paragraph.rb', line 66 def empty? content.empty? end |
#empty_copy ⇒ Object
78 79 80 81 82 83 |
# File 'lib/edifact_converter/xml/paragraph.rb', line 78 def empty_copy copy = Paragraph.new copy.format = format copy.font = font copy end |
#end_breaks? ⇒ Boolean
54 55 56 |
# File 'lib/edifact_converter/xml/paragraph.rb', line 54 def end_breaks? content.last.break? if content.any? end |
#ftx_format ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/edifact_converter/xml/paragraph.rb', line 85 def ftx_format text = "#{font}" text << case format when NORMAL '00' when CENTER '0M' when RIGHT '0H' when BOLD 'F0' when ITALIC 'K0' when UNDERLINE 'U0' else '00' end end |
#insert_split(text) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/edifact_converter/xml/paragraph.rb', line 157 def insert_split(text) index = text.string.rindex(/[\s]/) if index and index > 2 yield "#{text.string[0..(index)]}\\".encode "UTF-8" text.string[(index+1)..-1] else text.write '\\' yield text.string.encode "UTF-8" '' end end |
#remove_end_break ⇒ Object
50 51 52 |
# File 'lib/edifact_converter/xml/paragraph.rb', line 50 def remove_end_break content.shift if end_breaks? end |
#remove_start_break ⇒ Object
34 35 36 |
# File 'lib/edifact_converter/xml/paragraph.rb', line 34 def remove_start_break content.shift if start_breaks? end |
#start_breaks? ⇒ Boolean
38 39 40 |
# File 'lib/edifact_converter/xml/paragraph.rb', line 38 def start_breaks? content.first.break? if content.any? end |
#texts? ⇒ Boolean
74 75 76 |
# File 'lib/edifact_converter/xml/paragraph.rb', line 74 def texts? content.index { |obj| not obj.break? } end |
#to_s ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/edifact_converter/xml/paragraph.rb', line 169 def to_s txt = "<#{ftx_format}:" content.each do |obj| if obj.break? txt << "\n" else txt << obj.value end end txt << ">" end |
#to_subelms(next_paragraph) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/edifact_converter/xml/paragraph.rb', line 105 def to_subelms(next_paragraph) texts = [] text = StringIO.new content_clone = content.clone content_clone.delete_if do |obj| if obj.break? text.write '.' if text.size == 0 texts << text.string text.string = "" else text.string = divide_text(obj.value) { |t| texts << t } end true end text.seek text.size if text.size > 0 if next_paragraph if next_paragraph.start_breaks? next_paragraph.remove_start_break else if text.size == 70 last = text.chars.last text.seek 69 text.write('\\') texts << text.string text.string = "#{last}" text.seek text.size end text.write('\\') end end texts << text.string text.string = '' end texts end |