Sha256: d336a2704ff0445261f9aa484bbd96cc9c3e6b19171291910a249691060444b9

Contents?: true

Size: 815 Bytes

Versions: 10

Compression:

Stored size: 815 Bytes

Contents

require 'levenshteinish'

# str =~ /(s\d{2}e\d{2})/i && !(str =~ /#{$1}/i)

class Array
  def based_on(string, args = {})    
    result = self.any? ? self.map do|s|
      [Levenshtein.distance(s.title, string, args[:limit] || 0.4), s]
    end.reject do |value| 
      value.first.nil?
    end.sort_by do |value|
      value.first
    end.map(&:last).first : nil
    
    return if result.nil?
    
    # If the string contains a release date, then the results should do it to
    if result.title =~ /(s\d{2}e\d{2})/i
      return unless string.match(/#{$1}/i)
    end
    
    # If the {string} contains a year, then the found movie should return one to
    if result.title =~ /((19|20)\d{2})/
      return unless string.match(/#{$1}/)
    end
    
    # Yes i know, return isn't needed
    return result
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
undertexter-0.1.12 lib/undertexter/array.rb
undertexter-0.1.11 lib/undertexter/array.rb
undertexter-0.1.10 lib/undertexter/array.rb
undertexter-0.1.9 lib/undertexter/array.rb
undertexter-0.1.8 lib/undertexter/array.rb
undertexter-0.1.7 lib/undertexter/array.rb
undertexter-0.1.6 lib/undertexter/array.rb
undertexter-0.1.5 lib/undertexter/array.rb
undertexter-0.1.4 lib/undertexter/array.rb
undertexter-0.1.3 lib/undertexter/array.rb