class Column

Contain data information for every column Params:

Attributes

id[R]
index[R]
lang[R]
raw[R]
row[R]
simple[R]
type[R]

Public Class Methods

new(row, index, xml_data) click to toggle source

initialize Column @param row (Row) @param index (Integer) @param xml_data (XMLdata)

# File lib/asker/data/column.rb, line 16
def initialize(row, index, xml_data)
  @row    = row
  @index  = index
  @id     = "#{@row.id}.#{@index}"
  @raw    = ''
  @lang   = @row.langs[@index]
  @type   = @row.types[@index]
  @simple = { lang: true, type: true }
  read_data_from_xml(xml_data)
end

Public Instance Methods

to_html() click to toggle source
# File lib/asker/data/column.rb, line 27
def to_html
  case @type
  when 'text'
    return @raw
  when 'image_url'
    return "<img src=\"#{raw}\" alt\=\"image\">"
  when 'textfile_path'
    return "<pre>#{raw}</pre>"
  end
  "ERROR type #{@type}"
end

Private Instance Methods

read_data_from_xml(xml_data) click to toggle source
# File lib/asker/data/column.rb, line 41
def read_data_from_xml(xml_data)
  raise '[ERROR] Column with elements!' if xml_data.elements.count.positive?

  @raw = xml_data.text.strip.to_s

  # read attributes from XML input data
  read_lang_from_xml(xml_data)
  read_type_from_xml(xml_data)
end
read_lang_from_xml(xml_data) click to toggle source
# File lib/asker/data/column.rb, line 51
def read_lang_from_xml(xml_data)
  return unless xml_data.attributes['lang']

  code = xml_data.attributes['lang'].strip
  return if code == @lang.code

  @lang = LangFactory.instance.get(code)
  @simple[:lang] = false
  @row.simple_off(:lang)
end
read_type_from_xml(xml_data) click to toggle source
# File lib/asker/data/column.rb, line 62
def read_type_from_xml(xml_data)
  return unless xml_data.attributes['type']

  type = xml_data.attributes['type'].strip
  return if type == @type.to_s

  @type = type
  @simple[:type] = false
  @row.simple_off(:type)
end