Class: ODDB::HtmlTableHandler::Cell

Inherits:
Object
  • Object
show all
Defined in:
src/util/html_parser.rb

Constant Summary

MAX_WIDTH =
32

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Cell) initialize(attr, keep = false)

A new instance of Cell



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'src/util/html_parser.rb', line 168

def initialize(attr, keep=false)
  @keep_empty_lines = keep
  @attributes = attr.inject({}) { |inj, pair| 
    key, val = pair
    inj.store(key.downcase, val.gsub(/(^['"])|(['"])$/u, ''))
    inj
  }
  @current_line = ''
  @cdata = [@current_line]
  @children = []
  @colspan = [@attributes["colspan"].to_i, 1].max
  @rowspan = [@attributes["rowspan"].to_i, 1].max
  @current_formats = {}
  @formats = [@current_formats]
end

Instance Attribute Details

- (Object) attributes (readonly)

Returns the value of attribute attributes



166
167
168
# File 'src/util/html_parser.rb', line 166

def attributes
  @attributes
end

- (Object) children (readonly)

Returns the value of attribute children



166
167
168
# File 'src/util/html_parser.rb', line 166

def children
  @children
end

- (Object) colspan (readonly)

Returns the value of attribute colspan



166
167
168
# File 'src/util/html_parser.rb', line 166

def colspan
  @colspan
end

- (Object) rowspan (readonly)

Returns the value of attribute rowspan



166
167
168
# File 'src/util/html_parser.rb', line 166

def rowspan
  @rowspan
end

Instance Method Details

- (Object) _cdata(flatten = true)



196
197
198
199
200
201
202
# File 'src/util/html_parser.rb', line 196

def _cdata(flatten=true)
  cdata = @cdata.collect { |data|
    data.strip
  }
  cdata.delete('') unless @keep_empty_lines
  cdata
end

- (Object) add_child(child)



183
184
185
# File 'src/util/html_parser.rb', line 183

def add_child(child)
  @children.push(child)
end

- (Object) cdata



186
187
188
189
190
191
192
193
194
195
# File 'src/util/html_parser.rb', line 186

def cdata
  cdata = _cdata
  if(cdata.empty?)
    ''
  elsif(cdata.size == 1)
    cdata.first
  else
    cdata
  end
end

- (Object) formatted_cdata



203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'src/util/html_parser.rb', line 203

def formatted_cdata
  cdata = []
  @cdata.each_with_index { |data, idx|
    ddata = data.dup
    @formats[idx].sort.reverse.each { |pos, fmt|
      if(pos <= ddata.length)
        ddata[pos, 0] = fmt
      end
    }
    cdata << ddata
  }
  cdata
end

- (Object) height



216
217
218
# File 'src/util/html_parser.rb', line 216

def height
  _cdata.size
end

- (Object) next_line



219
220
221
222
223
224
# File 'src/util/html_parser.rb', line 219

def next_line
  @current_formats = {}
  @formats << @current_formats
  @current_line = ''
  @cdata << @current_line
end

- (Object) send_cdata(data)



225
226
227
228
229
# File 'src/util/html_parser.rb', line 225

def send_cdata(data)
  @current_line << data
  @current_line.gsub!(/\s+/u, ' ')
  @current_line
end

- (Object) send_format(fmtstr)



230
231
232
# File 'src/util/html_parser.rb', line 230

def send_format(fmtstr)
  @current_formats[@current_line.size] = fmtstr
end

- (Object) width



233
234
235
236
237
# File 'src/util/html_parser.rb', line 233

def width
  width = @cdata.collect { |line| 
    line.strip.size }.max
  (width.to_f / @colspan.to_f).ceil
end