class Angumine::SaxParser
Attributes
mined_data[RW]
name_to_branch[RW]
treepath[RW]
Public Class Methods
new(*args)
click to toggle source
# File lib/angumine/sax_parser.rb, line 8 def initialize(*args) self.treepath ||= [] self.name_to_branch ||= {} self.mined_data = [] end
Public Instance Methods
am_clean(s)
click to toggle source
# File lib/angumine/sax_parser.rb, line 19 def am_clean(s) s = s.join if s.is_a?(Array) s = s.strip end
am_clean_and_prefix_path(s)
click to toggle source
# File lib/angumine/sax_parser.rb, line 14 def am_clean_and_prefix_path(s) return unless s am_prefix_path(am_clean(s)) end
am_prefix_path(s)
click to toggle source
# File lib/angumine/sax_parser.rb, line 24 def am_prefix_path(s) return s if self.name_to_branch.length == 0 orig = s ending = '' non_var_name_index = s.index(/[\ \|]/) s, ending = *[s[0,non_var_name_index], s[non_var_name_index,s.length]] if non_var_name_index non_var_name_index = s.index('.') s, rest_of_val = *[s[0,non_var_name_index], s[non_var_name_index,s.length]] if non_var_name_index tree_branch_index = self.name_to_branch[s] if tree_branch_index "#{self.treepath[0..tree_branch_index].collect{|i|i[0]}.join('.')}#{rest_of_val}#{ending}" else orig end end
characters(s)
click to toggle source
# File lib/angumine/sax_parser.rb, line 62 def characters(s) s.scan(/{{([^}]*)}}/).each {|v|self.mined_data << "#{am_clean_and_prefix_path(v)}"} end
end_element(name)
click to toggle source
# File lib/angumine/sax_parser.rb, line 66 def end_element name self.treepath.last[1] -= 1 if self.treepath.last && self.treepath.last[1] > 0 end
start_element(name, attributes = [])
click to toggle source
# File lib/angumine/sax_parser.rb, line 42 def start_element name, attributes = [] if self.treepath.last self.treepath.last[1] += 1 if self.treepath.last[1] > 0 end Hash[attributes].each do |k,v| next unless v v = am_clean(v) if k.start_with?('ng-') && k != 'ng-class' && v if v.index(' in ') loop_data = v.split(' in ') arr = ["[#{loop_data[1]}]#{loop_data[0]}", 1] self.name_to_branch[loop_data[0]] = self.treepath.length # which currently is the next index self.treepath << arr else self.mined_data << "#{am_clean_and_prefix_path(v)}" end end end end