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.



100
101
102
103
104
105
# File 'lib/datasets/libsvm-dataset-list.rb', line 100

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

Instance Method Details

#tag_end(name) ⇒ Object



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

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



107
108
109
110
111
112
113
114
115
116
117
# File 'lib/datasets/libsvm-dataset-list.rb', line 107

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



135
136
137
# File 'lib/datasets/libsvm-dataset-list.rb', line 135

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