Closed lizrush closed 10 years ago
Heya - I do like the idea, but I don't think it's generic enough of a problem to make it's way into this library. But for fun here's a sample implementation:
# Compute possible dasherized variants
def tumblrize(str)
idxs = (0...str.length).select { |i| str[i] == '-' }
possibilities = (0..idxs.count + 1).flat_map { |s| idxs.combination(s).to_a }
possibilities.map do |possibility|
str.chars.reject.with_index { |c, idx| possibility.include?(idx) }.join
end
end
# Find the blogs with a given str (dasherized to the max)
def find_blogs(client, str)
tumblrize(str).map do |blog|
client.blog_info(blog) rescue nil
end.compact
end
# Usage
str = 'liz-m-rush'
tumblrize(str) # => ["liz-m-rush", "lizm-rush", "liz-mrush", "lizmrush"]
find_blogs(client, str) # <array of blogs that exist>
So, even though tumblr doesn't allow for fuzzy search, it would be nice to have the ability to have the client "tumblrize" search params for possible matches. What I mean by this is:
returns a Bad URI error.
This is simple enough to delete or sub out the whitespaces, however because tumblr is, well... tumblr, it is hard to predict whether a blog uses dashes or not. It would be awesome to have a client.tumblr_search type method that would return an array of blog_info for (in the case of above example) not only "liz-m-rush.tumblr.com" but also "lizmrush.tumblr.com" and other potential smushed together/dash combos where whitespace might be entered, like so:
would return (in the case that they exist):