Class: Table
- Inherits:
-
Object
- Object
- Table
- Defined in:
- lib/asker/data/table.rb
Instance Attribute Summary collapse
-
#datarows ⇒ Object
readonly
DEV: experimental replace for Row objects.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#langs ⇒ Object
readonly
Returns the value of attribute langs.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#rows ⇒ Object
readonly
Row objects are Datarows.raws values.
-
#sequence ⇒ Object
readonly
Returns the value of attribute sequence.
-
#simple ⇒ Object
readonly
Table is simple when all their rows and col has the same lang and type value.
Instance Method Summary collapse
-
#initialize(concept, xml_data) ⇒ Table
constructor
A new instance of Table.
- #sequence? ⇒ Boolean
-
#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.
- #to_s ⇒ Object
-
#types(index = :all) ⇒ Object
Return fields type: * types(:all) => Return an Array with all field types * types(index) => Return type for fields.
Constructor Details
#initialize(concept, xml_data) ⇒ Table
Returns a new instance of Table.
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
#datarows ⇒ Object (readonly)
DEV: experimental replace for Row objects
11 12 13 |
# File 'lib/asker/data/table.rb', line 11 def datarows @datarows end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
9 10 11 |
# File 'lib/asker/data/table.rb', line 9 def fields @fields end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/asker/data/table.rb', line 8 def id @id end |
#langs ⇒ Object (readonly)
Returns the value of attribute langs.
10 11 12 |
# File 'lib/asker/data/table.rb', line 10 def langs @langs end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/asker/data/table.rb', line 8 def name @name end |
#rows ⇒ Object (readonly)
Row objects are Datarows.raws values
12 13 14 |
# File 'lib/asker/data/table.rb', line 12 def rows @rows end |
#sequence ⇒ Object (readonly)
Returns the value of attribute sequence.
9 10 11 |
# File 'lib/asker/data/table.rb', line 9 def sequence @sequence end |
#simple ⇒ Object (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
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
57 58 59 |
# File 'lib/asker/data/table.rb', line 57 def simple_off(option) @simple[option] = false end |
#to_s ⇒ Object
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
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 |