Sha256: 8e0f0c717cb0be0dde5d7e1bd1418445cddc17520ecf00dd686b6bafc2dac81b
Contents?: true
Size: 1.2 KB
Versions: 3
Compression:
Stored size: 1.2 KB
Contents
module DeviceMap module Keyword # Deletes all non-alphanumeric characters from the given keywords def self.normalize(keywords) keywords.map do |keyword| # HACK: <tt>BUILDER_DATA_SOURCE</tt> contains keywords like: # <device id="BlackBerry 9650"> # <list> # <value>[Bb]lack.?[Bb]erry</value> # <value>blackberry 9650</value> # </list> # </device> # In such cases we want to replace patterns with simple keywords. keyword.downcase.gsub('[bb]', 'b').gsub(/[\W_]+/, '') end end # Concatenate all keywords together and skip duplicates def self.join(keywords) # HACK: This function handles the case when we want to concatenate all # keywords without duplication. # <device id="BlackBerry 9700"> # <list> # <value>blackberry</value> # <value>blackberry 9700</value> # </list> # </device> normalize(keywords).reduce('') do |result, keyword| if keyword.include?(result) keyword else result.concat(keyword) end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
device_map-0.1.2 | lib/device_map/keyword.rb |
device_map-0.1.1 | lib/device_map/keyword.rb |
device_map-0.1.0 | lib/device_map/keyword.rb |