polyrex-parser 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/polyrex-parser.rb +25 -16
 - metadata +3 -5
 
    
        data/lib/polyrex-parser.rb
    CHANGED
    
    | 
         @@ -34,18 +34,26 @@ class PolyrexParser 
     | 
|
| 
       34 
34 
     | 
    
         
             
              def parse(s)
         
     | 
| 
       35 
35 
     | 
    
         
             
                s.instance_eval{
         
     | 
| 
       36 
36 
     | 
    
         
             
                  def fetch_summary()
         
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
      
 37 
     | 
    
         
            +
                    name = 'summary'
         
     | 
| 
      
 38 
     | 
    
         
            +
                    self.slice(((self =~ /<#{name}>/) + name.length + 2) .. \
         
     | 
| 
      
 39 
     | 
    
         
            +
                      (self =~ /<\/#{name}>/m) - 1) if self[/<#{name}>/]
         
     | 
| 
      
 40 
     | 
    
         
            +
                        end
         
     | 
| 
      
 41 
     | 
    
         
            +
                        def fetch_records()
         
     | 
| 
      
 42 
     | 
    
         
            +
                    name = 'records'
         
     | 
| 
      
 43 
     | 
    
         
            +
                
         
     | 
| 
      
 44 
     | 
    
         
            +
                    result = ''
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                    if self[/<#{name}/] then
         
     | 
| 
      
 47 
     | 
    
         
            +
                      result = self.slice(((self =~ /<#{name}/) + name.length + 2) .. \
         
     | 
| 
      
 48 
     | 
    
         
            +
                        (self.rindex(/<\/#{name}>/m)) - 1) if self[/<\/#{name}/]
         
     | 
| 
      
 49 
     | 
    
         
            +
                    end
         
     | 
| 
      
 50 
     | 
    
         
            +
                    result
         
     | 
| 
       45 
51 
     | 
    
         
             
                  end
         
     | 
| 
       46 
52 
     | 
    
         
             
                }
         
     | 
| 
       47 
53 
     | 
    
         | 
| 
       48 
     | 
    
         
            -
                 
     | 
| 
      
 54 
     | 
    
         
            +
                result = s.match(/<(\w+)(\s[^\/>]+)?/)
         
     | 
| 
      
 55 
     | 
    
         
            +
                root_name, raw_attributes = result.captures if result
         
     | 
| 
      
 56 
     | 
    
         
            +
                puts 'result : '  + result.inspect
         
     | 
| 
       49 
57 
     | 
    
         
             
                attributes = get_attributes(raw_attributes) if raw_attributes
         
     | 
| 
       50 
58 
     | 
    
         
             
                raw_summary = s.fetch_summary
         
     | 
| 
       51 
59 
     | 
    
         | 
| 
         @@ -55,8 +63,9 @@ class PolyrexParser 
     | 
|
| 
       55 
63 
     | 
    
         
             
                records = nil
         
     | 
| 
       56 
64 
     | 
    
         | 
| 
       57 
65 
     | 
    
         | 
| 
       58 
     | 
    
         
            -
                if raw_records then
         
     | 
| 
      
 66 
     | 
    
         
            +
                if raw_records and raw_records[/<\w+/] then
         
     | 
| 
       59 
67 
     | 
    
         | 
| 
      
 68 
     | 
    
         
            +
                  puts 'raw_records : ' + raw_records.inspect
         
     | 
| 
       60 
69 
     | 
    
         
             
                  node_name = raw_records[/<(\w+)/,1]
         
     | 
| 
       61 
70 
     | 
    
         | 
| 
       62 
71 
     | 
    
         
             
                  #record_threads = raw_records.strip.split(/(?=<#{node_name}[^>]*>)/).map do |x| 
         
     | 
| 
         @@ -65,15 +74,15 @@ class PolyrexParser 
     | 
|
| 
       65 
74 
     | 
    
         
             
                  i = 0
         
     | 
| 
       66 
75 
     | 
    
         | 
| 
       67 
76 
     | 
    
         
             
                  while i < raw_records.strip.length do
         
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
      
 77 
     | 
    
         
            +
                    i = scan_s(raw_records, node_name, i) + 1
         
     | 
| 
      
 78 
     | 
    
         
            +
                    a << i
         
     | 
| 
       70 
79 
     | 
    
         
             
                  end
         
     | 
| 
       71 
80 
     | 
    
         | 
| 
       72 
81 
     | 
    
         | 
| 
       73 
82 
     | 
    
         
             
                  record_threads = ([0] + a).each_cons(2).map do |s1, s2|
         
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
      
 83 
     | 
    
         
            +
                    raw_s = raw_records[s1...s2]
         
     | 
| 
       75 
84 
     | 
    
         | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
      
 85 
     | 
    
         
            +
                    Thread.new{ Thread.current[:record] = parse(raw_s) }
         
     | 
| 
       77 
86 
     | 
    
         
             
                  end
         
     | 
| 
       78 
87 
     | 
    
         
             
                  records = record_threads.map{|x| x.join; x[:record]}
         
     | 
| 
       79 
88 
     | 
    
         | 
| 
         @@ -94,9 +103,9 @@ class PolyrexParser 
     | 
|
| 
       94 
103 
     | 
    
         
             
                  scan_s(s, node_name, instances+1, i + r + l)
         
     | 
| 
       95 
104 
     | 
    
         
             
                else
         
     | 
| 
       96 
105 
     | 
    
         
             
                  if instances > 1 then
         
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
      
 106 
     | 
    
         
            +
                    scan_s(s, node_name, instances - 1, i + r + node_name.length + 3)
         
     | 
| 
       98 
107 
     | 
    
         
             
                  else
         
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
      
 108 
     | 
    
         
            +
                    return i + r + node_name.length + 2
         
     | 
| 
       100 
109 
     | 
    
         
             
                  end
         
     | 
| 
       101 
110 
     | 
    
         
             
                end
         
     | 
| 
       102 
111 
     | 
    
         | 
    
        metadata
    CHANGED
    
    | 
         @@ -2,7 +2,7 @@ 
     | 
|
| 
       2 
2 
     | 
    
         
             
            name: polyrex-parser
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
4 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       5 
     | 
    
         
            -
              version: 0.3. 
     | 
| 
      
 5 
     | 
    
         
            +
              version: 0.3.2
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors: 
         
     | 
| 
       8 
8 
     | 
    
         
             
            - James Robertson
         
     | 
| 
         @@ -10,8 +10,7 @@ autorequire: 
     | 
|
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
            date: 2012- 
     | 
| 
       14 
     | 
    
         
            -
            default_executable: 
         
     | 
| 
      
 13 
     | 
    
         
            +
            date: 2012-10-07 00:00:00 Z
         
     | 
| 
       15 
14 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       16 
15 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
       17 
16 
     | 
    
         
             
              name: recordx-parser
         
     | 
| 
         @@ -34,7 +33,6 @@ extra_rdoc_files: [] 
     | 
|
| 
       34 
33 
     | 
    
         | 
| 
       35 
34 
     | 
    
         
             
            files: 
         
     | 
| 
       36 
35 
     | 
    
         
             
            - lib/polyrex-parser.rb
         
     | 
| 
       37 
     | 
    
         
            -
            has_rdoc: true
         
     | 
| 
       38 
36 
     | 
    
         
             
            homepage: 
         
     | 
| 
       39 
37 
     | 
    
         
             
            licenses: []
         
     | 
| 
       40 
38 
     | 
    
         | 
| 
         @@ -58,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       58 
56 
     | 
    
         
             
            requirements: []
         
     | 
| 
       59 
57 
     | 
    
         | 
| 
       60 
58 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       61 
     | 
    
         
            -
            rubygems_version: 1. 
     | 
| 
      
 59 
     | 
    
         
            +
            rubygems_version: 1.8.23
         
     | 
| 
       62 
60 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       63 
61 
     | 
    
         
             
            specification_version: 3
         
     | 
| 
       64 
62 
     | 
    
         
             
            summary: polyrex-parser
         
     |