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

initialize Table object

Parameters:



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

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

Return true if table has a sequence defined

Returns:

  • (Boolean)


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

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)


62
63
64
# File 'lib/asker/data/table.rb', line 62

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

#to_sObject

Return table name



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

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)


50
51
52
53
54
55
# File 'lib/asker/data/table.rb', line 50

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

  @types[index]
end