Class: Datasets::LIBSVMDatasetList::IndexListener

Inherits:
Object
  • Object
show all
Includes:
REXML::StreamListener
Defined in:
lib/datasets/libsvm-dataset-list.rb

Instance Method Summary collapse

Constructor Details

#initialize(abort_tag, &block) ⇒ IndexListener

Returns a new instance of IndexListener.



103
104
105
106
107
108
# File 'lib/datasets/libsvm-dataset-list.rb', line 103

def initialize(abort_tag, &block)
  @abort_tag = abort_tag
  @block = block
  @row = nil
  @in_td = false
end

Instance Method Details

#tag_end(name) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/datasets/libsvm-dataset-list.rb', line 122

def tag_end(name)
  case name
  when "table"
    throw(@abort_tag)
  when "tr"
    name_column = @row[0]
    return unless name_column
    record = Record.new
    record.name = name_column[:text]
    record.files = []
    @block.call(name_column[:href], record)
  when "td"
    @in_td = false
  end
end

#tag_start(name, attributes) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
# File 'lib/datasets/libsvm-dataset-list.rb', line 110

def tag_start(name, attributes)
  case name
  when "tr"
    @row = []
  when "td"
    @in_td = true
    @row << {:text => ""}
  when "a"
    @row.last[:href] = attributes["href"] if @in_td
  end
end

#text(data) ⇒ Object



138
139
140
# File 'lib/datasets/libsvm-dataset-list.rb', line 138

def text(data)
  @row.last[:text] << data if @in_td
end