Sha256: 04c08a22e4dd45e123ac7568a0139a7eed4a0296d62456b4e1d868f6c7cb1d5f

Contents?: true

Size: 402 Bytes

Versions: 4

Compression:

Stored size: 402 Bytes

Contents

require 'iconv'

module Lunar
  class Words < Array
    SEPARATOR = /\s+/

    def initialize(str)
      words = str.split(SEPARATOR).
        reject { |w| w.to_s.strip.empty? }.
        map    { |w| sanitize(w) }
      
      super(words)
    end

  private
    def sanitize(str)
      Iconv.iconv('UTF-8//IGNORE', 'UTF-8', str)[0].to_s.
        gsub(/[^a-zA-Z0-9\-_]/, '').downcase
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lunar-0.4.1 lib/lunar/words.rb
lunar-0.4.0 lib/lunar/words.rb
lunar-0.3.0 lib/lunar/words.rb
lunar-0.2.3 lib/lunar/words.rb