Class: VORuby::ActiveVOTable::Callbacks

Inherits:
Object
  • Object
show all
Includes:
XML::SaxParser::Callbacks
Defined in:
lib/voruby/active_votable/active_votable.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_class) ⇒ Callbacks

Returns a new instance of Callbacks.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/voruby/active_votable/active_votable.rb', line 19

def initialize(base_class)
  self.base_class = base_class
  
  self.row = []
  self. = []
  
  self.meta_location = OpenStruct.new(:resource => 0, :table => 0, :field => 0)
  self.data_location = OpenStruct.new(:resource => 0, :table => 0, :row => 0, :column => 0)
  self.inside_td = false
  self.in_error = false
end

Instance Attribute Details

#base_classObject

Returns the value of attribute base_class.



15
16
17
# File 'lib/voruby/active_votable/active_votable.rb', line 15

def base_class
  @base_class
end

#data_locationObject

Returns the value of attribute data_location.



15
16
17
# File 'lib/voruby/active_votable/active_votable.rb', line 15

def data_location
  @data_location
end

#data_tablesObject

Returns the value of attribute data_tables.



15
16
17
# File 'lib/voruby/active_votable/active_votable.rb', line 15

def data_tables
  @data_tables
end

#fields_tablesObject

Returns the value of attribute fields_tables.



15
16
17
# File 'lib/voruby/active_votable/active_votable.rb', line 15

def fields_tables
  @fields_tables
end

#in_errorObject

Returns the value of attribute in_error.



15
16
17
# File 'lib/voruby/active_votable/active_votable.rb', line 15

def in_error
  @in_error
end

#inside_tdObject

Returns the value of attribute inside_td.



15
16
17
# File 'lib/voruby/active_votable/active_votable.rb', line 15

def inside_td
  @inside_td
end

#meta_locationObject

Returns the value of attribute meta_location.



15
16
17
# File 'lib/voruby/active_votable/active_votable.rb', line 15

def meta_location
  @meta_location
end

#metadataObject

Returns the value of attribute metadata.



15
16
17
# File 'lib/voruby/active_votable/active_votable.rb', line 15

def 
  @metadata
end

#rowObject

Returns the value of attribute row.



15
16
17
# File 'lib/voruby/active_votable/active_votable.rb', line 15

def row
  @row
end

Instance Method Details

#data_table_nameObject



89
90
91
# File 'lib/voruby/active_votable/active_votable.rb', line 89

def data_table_name
  "#{self.base_class.table_name}_#{Base::DATA_ID}_#{self.data_location.resource}_#{self.data_location.table}"
end

#fields_table_nameObject



93
94
95
# File 'lib/voruby/active_votable/active_votable.rb', line 93

def fields_table_name
  "#{self.base_class.table_name}_#{Base::SCHEMA_ID}_#{self.meta_location.resource}_#{self.meta_location.table}"
end

#on_characters(chars) ⇒ Object



84
85
86
87
# File 'lib/voruby/active_votable/active_votable.rb', line 84

def on_characters(chars)
  raise "Query status error: #{chars}" if self.in_error
  self.row << chars if self.inside_td
end

#on_end_element(name) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/voruby/active_votable/active_votable.rb', line 69

def on_end_element(name)
  case name
  when 'TABLE'
    self..clear
  when 'TABLEDATA'
    self.base_class.connection.commit_db_transaction()
  when 'TR'
    create_record()
  when 'TD'
    self.inside_td = false
  when 'INFO'
    self.in_error = false
  end
end

#on_start_element(name, attrs) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/voruby/active_votable/active_votable.rb', line 31

def on_start_element(name, attrs)
  case name
  when 'RESOURCE'
    self.meta_location.resource += 1
    self.data_location.resource += 1
    self.meta_location.table = 0
    self.data_location.table = 0
  when 'TABLE'
    self.meta_location.table += 1
    self.meta_location.field = 0

    self.data_location.table += 1
    self.data_location.row = 0
    self.data_location.column = 0
    
    create_db_tables()
  when 'FIELD'
    self.meta_location.field += 1
    self. << attrs
  when 'DATA'
    create_data_schema() # create the table and make it available
    ()
  when 'TABLEDATA'
    self.base_class.connection.begin_db_transaction()
  when 'TR'
    self.data_location.resource = self.meta_location.resource
    self.data_location.table = self.meta_location.table
    self.data_location.row += 1
    self.data_location.column = 0
    self.row.clear
  when 'TD'
    self.data_location.column += 1
    self.inside_td = true
  when 'INFO'
    self.in_error = true if attrs['name'] == 'QUERY_STATUS' and attrs['value'] == 'ERROR'
  end
end