Commits

Kaspar Schiess  committed 5f37cd6

HashParser now deals with spaces and complex attributes

  • Participants
  • Parent commits 2c3d7af

Comments (0)

Files changed (4)

 source "https://rubygems.org"
 
 gem 'mixlib-shellout'
-gem 'clamp'
+gem 'clamp'
+
+group :test do
+  gem 'rspec'
+end

File Gemfile.lock

   remote: https://rubygems.org/
   specs:
     clamp (0.5.0)
+    diff-lcs (1.1.3)
     mixlib-shellout (1.1.0)
+    rspec (2.12.0)
+      rspec-core (~> 2.12.0)
+      rspec-expectations (~> 2.12.0)
+      rspec-mocks (~> 2.12.0)
+    rspec-core (2.12.1)
+    rspec-expectations (2.12.0)
+      diff-lcs (~> 1.1.3)
+    rspec-mocks (2.12.0)
 
 PLATFORMS
   ruby
 DEPENDENCIES
   clamp
   mixlib-shellout
+  rspec

File lib/iscsi/hash_parser.rb

       str.lines do |line| 
         line.chomp!
         
-        if md=line.match(/^(?<indent>\s*)(?<key>\w+)\s*: (?<val>.*)$/)
+        if md=line.match(/^(?<indent>\s*)(?<key>(\w|\s)+)\s*: (?<val>.*)$/)
           indent = md[:indent].size
           
           # Reset the current hash?
             result << current
           end
 
-          current[md[:key].downcase.to_sym] = md[:val]
+          current[transform_key(md[:key])] = md[:val]
           
           last_indent = indent
         end
 
       result
     end
+    
+    def transform_key(str)
+      str.
+        strip.
+        gsub(' ', '_').
+        downcase.
+        to_sym
+    end
   end
 end

File spec/lib/iscsi/hash_parser_spec.rb

       result[0][:target].should == 'iqn.2010-08.org.illumos:02:6140505e-fb64-6670-b44d-c3395b9bb201'
       result[1][:target].should == 'iqn.2010-08.org.illumos:02:6140505e-fb64-6670-b412321321312121'
     end
+    describe 'first result' do
+      slet(:first) { result.first }
+      
+      it "contains a :provider_name" do
+        p first
+        first[:provider_name].should == 'iscsit' 
+      end 
+    end 
   end
 end