Class: Nostr::Filter
- Inherits:
-
Object
- Object
- Nostr::Filter
- Defined in:
- lib/nostr/filter.rb
Overview
A filter determines what events will be sent in a subscription.
Instance Attribute Summary collapse
-
#authors ⇒ Array<String>?
readonly
A list of pubkeys, the pubkey of an event must be one of these.
-
#e ⇒ Array<String>?
readonly
A list of event ids that are referenced in an “e” tag.
-
#ids ⇒ Array<String>?
readonly
A list of event ids.
-
#kinds ⇒ Array<Integer>?
readonly
A list of a kind numbers.
-
#limit ⇒ Integer?
readonly
Maximum number of events to be returned in the initial query.
-
#p ⇒ Array<String>?
readonly
A list of pubkeys that are referenced in a “p” tag.
-
#since ⇒ Integer?
readonly
A timestamp, events must be newer than this to pass.
-
#until ⇒ Integer?
readonly
A timestamp, events must be older than this to pass.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares two filters.
-
#initialize(**kwargs) ⇒ Filter
constructor
Instantiates a new Filter.
-
#to_h ⇒ Hash
Converts the filter to a hash, removing all empty attributes.
Constructor Details
#initialize(**kwargs) ⇒ Filter
Instantiates a new Filter
of these
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/nostr/filter.rb', line 120 def initialize(**kwargs) @ids = kwargs[:ids] @authors = kwargs[:authors] @kinds = kwargs[:kinds] @e = kwargs[:e] @p = kwargs[:p] @since = kwargs[:since] @until = kwargs[:until] @limit = kwargs[:limit] end |
Instance Attribute Details
#authors ⇒ Array<String>? (readonly)
A list of pubkeys, the pubkey of an event must be one of these
26 27 28 |
# File 'lib/nostr/filter.rb', line 26 def @authors end |
#e ⇒ Array<String>? (readonly)
A list of event ids that are referenced in an “e” tag
48 49 50 |
# File 'lib/nostr/filter.rb', line 48 def e @e end |
#ids ⇒ Array<String>? (readonly)
A list of event ids
15 16 17 |
# File 'lib/nostr/filter.rb', line 15 def ids @ids end |
#kinds ⇒ Array<Integer>? (readonly)
A list of a kind numbers
37 38 39 |
# File 'lib/nostr/filter.rb', line 37 def kinds @kinds end |
#limit ⇒ Integer? (readonly)
Maximum number of events to be returned in the initial query
92 93 94 |
# File 'lib/nostr/filter.rb', line 92 def limit @limit end |
#p ⇒ Array<String>? (readonly)
A list of pubkeys that are referenced in a “p” tag
59 60 61 |
# File 'lib/nostr/filter.rb', line 59 def p @p end |
#since ⇒ Integer? (readonly)
A timestamp, events must be newer than this to pass
70 71 72 |
# File 'lib/nostr/filter.rb', line 70 def since @since end |
#until ⇒ Integer? (readonly)
A timestamp, events must be older than this to pass
81 82 83 |
# File 'lib/nostr/filter.rb', line 81 def until @until end |
Instance Method Details
#==(other) ⇒ Boolean
Compares two filters. Returns true if all attributes are equal and false otherwise
171 172 173 |
# File 'lib/nostr/filter.rb', line 171 def ==(other) to_h == other.to_h end |
#to_h ⇒ Hash
Converts the filter to a hash, removing all empty attributes
149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/nostr/filter.rb', line 149 def to_h { ids:, authors:, kinds:, '#e': e, '#p': p, since:, until: self.until, limit: }.compact end |