Skip to content

Add filtering and search methods #44

@cardmagic

Description

@cardmagic

Summary

Add methods to filter and search items by common criteria.

Proposed Features

items_since(time)

Filter items published after a given time:

def items_since(time)
  items.select do |item|
    date = item[:pubDate] || item[:updated] || item[:published]
    date && date > time
  end
end

Usage:

rss.items_since(1.day.ago)
rss.items_since(Time.parse('2024-01-01'))

items_by_category(name)

Filter items by category:

def items_by_category(name)
  items.select do |item|
    cat = item[:category]
    case cat
    when Array then cat.any? { |c| c.to_s.downcase.include?(name.downcase) }
    when String then cat.downcase.include?(name.downcase)
    end
  end
end

Usage:

rss.items_by_category('technology')

search(query)

Simple text search across title and description:

def search(query)
  pattern = Regexp.new(Regexp.escape(query), Regexp::IGNORECASE)
  items.select do |item|
    [item[:title], item[:description], item[:summary], item[:content]].any? do |field|
      field.to_s =~ pattern
    end
  end
end

Usage:

rss.search('ruby')
rss.search('breaking news')

Benefits

  • Common operations without manual filtering
  • Consistent date handling across RSS/Atom formats
  • Case-insensitive matching by default

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions