Sha256: 99477e12ade7fe41e960db55d874f1f41e2e0cc8a8684829446d79a53669ad6f
Contents?: true
Size: 660 Bytes
Versions: 9
Compression:
Stored size: 660 Bytes
Contents
class LooseTightDictionary # A tightener just strips a string down to its core class Tightener attr_reader :regexp def initialize(regexp_or_str) @regexp = regexp_or_str.to_regexp 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
9 entries across 9 versions & 1 rubygems