Skip to content

Instantly share code, notes, and snippets.

@msassak
Created July 2, 2010 05:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msassak/460971 to your computer and use it in GitHub Desktop.
Save msassak/460971 to your computer and use it in GitHub Desktop.
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