Class: Angumine::SaxParser
- Inherits:
-
Nokogiri::XML::SAX::Document
- Object
- Nokogiri::XML::SAX::Document
- Angumine::SaxParser
- Defined in:
- lib/angumine/sax_parser.rb
Instance Attribute Summary collapse
-
#mined_data ⇒ Object
Returns the value of attribute mined_data.
-
#name_to_branch ⇒ Object
Returns the value of attribute name_to_branch.
-
#treepath ⇒ Object
Returns the value of attribute treepath.
Instance Method Summary collapse
- #am_clean(s) ⇒ Object
- #am_clean_and_prefix_path(s) ⇒ Object
- #am_prefix_path(s) ⇒ Object
- #characters(s) ⇒ Object
- #end_element(name) ⇒ Object
-
#initialize(*args) ⇒ SaxParser
constructor
A new instance of SaxParser.
- #start_element(name, attributes = []) ⇒ Object
Constructor Details
#initialize(*args) ⇒ SaxParser
Returns a new instance of SaxParser.
8 9 10 11 12 |
# File 'lib/angumine/sax_parser.rb', line 8 def initialize(*args) self.treepath ||= [] self.name_to_branch ||= {} self.mined_data = [] end |
Instance Attribute Details
#mined_data ⇒ Object
Returns the value of attribute mined_data.
6 7 8 |
# File 'lib/angumine/sax_parser.rb', line 6 def mined_data @mined_data end |
#name_to_branch ⇒ Object
Returns the value of attribute name_to_branch.
6 7 8 |
# File 'lib/angumine/sax_parser.rb', line 6 def name_to_branch @name_to_branch end |
#treepath ⇒ Object
Returns the value of attribute treepath.
6 7 8 |
# File 'lib/angumine/sax_parser.rb', line 6 def treepath @treepath end |
Instance Method Details
#am_clean(s) ⇒ Object
19 20 21 22 |
# 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) ⇒ Object
14 15 16 17 |
# 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) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# 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) ⇒ Object
62 63 64 |
# 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) ⇒ Object
66 67 68 |
# 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 = []) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# 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 |