Class: Table

Inherits:
Object
  • Object
show all
Defined in:
lib/asker/data/table.rb

Overview

Contains data table information

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(concept, xml_data) ⇒ Table

Returns a new instance of Table.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/asker/data/table.rb', line 13

def initialize(concept, xml_data)
  @concept = concept

  # read attributes from XML data
  t = xml_data.attributes['fields'].to_s.strip.split(',')
  t.each { |i| i.strip! }
  @fields = t || []
  @types  = ['text']        * @fields.size
  @langs  = [@concept.lang] * @fields.size

  @name   = ''
  @fields.each { |i| @name=@name + '$' + i.to_s.strip.downcase}
  @id     = @concept.name.to_s + '.' + @name
  @simple = { lang: true, type: true }

  @sequence = []
  if xml_data.attributes['sequence']
    t = xml_data.attributes['sequence'].to_s || ""
    @sequence = t.split(",")
    # puts "[DEPRECATED] sequence attr on table <#{@name}>"
  end

  @datarows = [] #DEV experiment replace row data with row objects
  read_data_from_xml(xml_data)
  @rows = @datarows.map { |r| r.raws }
end

Instance Attribute Details

#datarowsObject (readonly)

Returns the value of attribute datarows.



10
11
12
# File 'lib/asker/data/table.rb', line 10

def datarows
  @datarows
end

#fieldsObject (readonly)

Returns the value of attribute fields.



9
10
11
# File 'lib/asker/data/table.rb', line 9

def fields
  @fields
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/asker/data/table.rb', line 8

def id
  @id
end

#langsObject (readonly)

Returns the value of attribute langs.



9
10
11
# File 'lib/asker/data/table.rb', line 9

def langs
  @langs
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/asker/data/table.rb', line 8

def name
  @name
end

#rowsObject (readonly)

Returns the value of attribute rows.



10
11
12
# File 'lib/asker/data/table.rb', line 10

def rows
  @rows
end

#sequenceObject (readonly)

Returns the value of attribute sequence.



9
10
11
# File 'lib/asker/data/table.rb', line 9

def sequence
  @sequence
end

#simpleObject (readonly)

Returns the value of attribute simple.



11
12
13
# File 'lib/asker/data/table.rb', line 11

def simple
  @simple
end

#types(index = :all) ⇒ Object (readonly)

Returns the value of attribute types.



9
10
11
# File 'lib/asker/data/table.rb', line 9

def types
  @types
end

Instance Method Details

#sequence?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/asker/data/table.rb', line 44

def sequence?
  @sequence.size > 0
end

#simple_off(option) ⇒ Object



54
55
56
# File 'lib/asker/data/table.rb', line 54

def simple_off(option)
  @simple[option] = false
end

#to_sObject



40
41
42
# File 'lib/asker/data/table.rb', line 40

def to_s
  @name.to_s
end