X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=lib%2Ferd_handler%2Flabel.rb;h=9369190ad12ba4e633e00f74fd0244b6446962b3;hb=HEAD;hp=ad816182ff4be9c58f62ff53819c26579862cfab;hpb=042a27abb3ac3bf9faf36406204fe1d1901123d3;p=erd-marker.git diff --git a/lib/erd_handler/label.rb b/lib/erd_handler/label.rb index ad81618..9369190 100644 --- a/lib/erd_handler/label.rb +++ b/lib/erd_handler/label.rb @@ -2,22 +2,22 @@ class Label attr_reader :original, :processed - def initialize(original) + def initialize(original, auto_tidy = false) @original = original @processed = [original] + self.tidy if auto_tidy end def split(opts = {}) + regexp = /[\t\n _,.-]+/ + split_camel_case = true + split_numbers = true if opts.class == Regexp regexp = opts - split_camel_case = true else - regexp = opts[:regexp] || /[ _,.-]+/ - if opts.has_key? :camel_case - split_camel_case = opts[:camel_case] - else - split_camel_case = true - end + regexp = opts[:rexexp] if opts.has_key? :regexp + split_camel_case = opts[:camel_case] if opts.has_key? :camel_case + split_numbers = opts[:numbers] if opts.has_key? :numbers end @processed = @processed.map do |segment| segment.split(regexp) @@ -25,7 +25,13 @@ class Label if split_camel_case @processed = @processed.map do |segment| - segment.split(/(?=[A-Z])/) + segment.split(/(?<=[a-z])(?=[A-Z])/) + end.flatten + end + + if split_numbers + @processed = @processed.map do |segment| + segment.split(/(?:(?