Class: Table

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(concept, xml_data) ⇒ Table

Returns a new instance of Table.

Parameters:



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/asker/data/table.rb', line 19

def initialize(concept, xml_data)
  @concept = concept
  read_attributes_from_xml(xml_data)

  @simple = {lang: true, type: true}
  @types = ["text"] * @fields.size
  @langs = [@concept.lang] * @fields.size

  @datarows = [] # DEV experiment replace row data with row objects
  read_data_from_xml(xml_data)
  @rows = @datarows.map(&:raws)
end

Instance Attribute Details

#datarowsObject (readonly)

DEV: experimental replace for Row objects



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

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.



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

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)

Row objects are Datarows.raws values



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

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)

Table is simple when all their rows and col has the same lang and type value



14
15
16
# File 'lib/asker/data/table.rb', line 14

def simple
  @simple
end

Instance Method Details

#sequence?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/asker/data/table.rb', line 36

def sequence?
  @sequence.size.positive?
end

#simple_off(option) ⇒ Object

Set table to simple off

  • simple_off(:lang) => Set table simple lang FALSE

  • simple_off(:type) => Set table simple type FALSE

Parameters:

  • option (Symbol)


57
58
59
# File 'lib/asker/data/table.rb', line 57

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

#to_sObject



32
33
34
# File 'lib/asker/data/table.rb', line 32

def to_s
  @name.to_s
end

#types(index = :all) ⇒ Object

Return fields type:

  • types(:all) => Return an Array with all field types

  • types(index) => Return type for fields

Parameters:

  • index (Integer) (defaults to: :all)


45
46
47
48
49
50
# File 'lib/asker/data/table.rb', line 45

def types(index = :all)
  @types = (["text"] * @fields.size) if @types.nil?
  return @types if index == :all

  @types[index]
end