module RssLookup
Public Instance Methods
Source
# File lib/rss_lookup.rb, line 17 def find_feed_by_label(feeds, label) needle = normalize_label(label) return { error: "Feed not found" } if needle.empty? matches = feeds.select do |feed| hay = normalize_label(feed["title"]) hay.include?(needle) || needle.include?(hay) end case matches.length when 0 { error: "Feed not found" } when 1 { feed: matches.first } else titles = matches.map { |feed| feed["title"] }.join(", ") { error: "Multiple feeds match — be more specific: #{titles}" } end end
Source
# File lib/rss_lookup.rb, line 13 def normalize_label(value) TextUtil.squish(value.to_s).gsub(/[\[\]]/, "").downcase end