Sha256: 84f85c03a1eac80209233ce2e854888e68f83e2bcf1841cc32154065bc60c22f
Contents?: true
Size: 696 Bytes
Versions: 2
Compression:
Stored size: 696 Bytes
Contents
class LooseTightDictionary # A tightener just strips a string down to its core class Tightener include ExtractRegexp attr_reader :regexp def initialize(regexp_or_str) @regexp = extract_regexp regexp_or_str end # A tightener applies when its regexp matches and captures a new (shorter) string def apply?(str) !!(regexp.match(str)) end # The result of applying a tightener is just all the captures put together. def apply(str) if match_data = regexp.match(str) match_data.captures.join else str end end def inspect "#<Tightener regexp=#{regexp.inspect}>" end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
loose_tight_dictionary-0.1.1 | lib/loose_tight_dictionary/tightener.rb |
loose_tight_dictionary-0.1.0 | lib/loose_tight_dictionary/tightener.rb |