Created
July 2, 2010 05:23
-
-
Save msassak/460971 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'strscan' | |
singleton = <<EOS | |
Feature: Singletonz | |
Scenario: Oh hai | |
Given what is this here | |
%_FEATURE_END_% | |
EOS | |
multi =<<EOS | |
Feature: Foo | |
Scenario: bar | |
Given blah | |
%_FEATURE_END_% | |
Feature: Bar | |
Scenario: blargle | |
Given fooble | |
%_FEATURE_END_% | |
Feature: Boogle | |
Scenario: mople | |
When floogle | |
%_FEATURE_END_% | |
EOS | |
class FeatureScanner | |
FEATURE_END = /%_FEATURE_END_%/ | |
def scan(input) | |
features = [] | |
scanner = StringScanner.new(input) | |
if scanner.exist?(FEATURE_END) | |
loop do | |
feature = scanner.scan_until(FEATURE_END) | |
break unless feature | |
features << clean_feature(feature) | |
end | |
else | |
features << scanner.string | |
end | |
features | |
end | |
def clean_feature(str) | |
str.chomp("%_FEATURE_END_%").strip | |
end | |
end | |
f = FeatureScanner.new | |
p f.scan(multi) | |
p f.scan(singleton) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment