Class: Nostr::Filter
- Inherits:
-
Object
- Object
- Nostr::Filter
- Defined in:
- lib/filter.rb
Instance Attribute Summary collapse
-
#authors ⇒ Object
readonly
Returns the value of attribute authors.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#kinds ⇒ Object
readonly
Returns the value of attribute kinds.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#search ⇒ Object
readonly
Returns the value of attribute search.
-
#since ⇒ Object
readonly
Returns the value of attribute since.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#until ⇒ Object
readonly
Returns the value of attribute until.
Instance Method Summary collapse
-
#initialize(ids: nil, kinds: nil, authors: nil, since: nil, limit: nil, search: nil, **params) ⇒ Filter
constructor
A new instance of Filter.
- #to_h ⇒ Object
Constructor Details
#initialize(ids: nil, kinds: nil, authors: nil, since: nil, limit: nil, search: nil, **params) ⇒ Filter
Returns a new instance of Filter.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/filter.rb', line 15 def initialize(ids: nil, kinds: nil, authors: nil, since: nil, limit: nil, search: nil, **params) @id = id @kinds = kinds @authors = @tags = @since = since.nil? ? nil : since.to_i @limit = limit @search = search @until = params[:until].nil? ? nil : params[:until].to_i # this is an hack to permit the use of the 'until' param, since it is a reserved word # Handle additional parameters with a-zA-Z names params.each do |key, value| if key.to_s.match?(/\A[a-zA-Z]\z/) instance_variable_set("@#{key}", value) end end end |
Instance Attribute Details
#authors ⇒ Object (readonly)
Returns the value of attribute authors.
6 7 8 |
# File 'lib/filter.rb', line 6 def @authors end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/filter.rb', line 4 def id @id end |
#kinds ⇒ Object (readonly)
Returns the value of attribute kinds.
5 6 7 |
# File 'lib/filter.rb', line 5 def kinds @kinds end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
10 11 12 |
# File 'lib/filter.rb', line 10 def limit @limit end |
#search ⇒ Object (readonly)
Returns the value of attribute search.
11 12 13 |
# File 'lib/filter.rb', line 11 def search @search end |
#since ⇒ Object (readonly)
Returns the value of attribute since.
8 9 10 |
# File 'lib/filter.rb', line 8 def since @since end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
7 8 9 |
# File 'lib/filter.rb', line 7 def @tags end |
#until ⇒ Object (readonly)
Returns the value of attribute until.
9 10 11 |
# File 'lib/filter.rb', line 9 def until @until end |
Instance Method Details
#to_h ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/filter.rb', line 33 def to_h result = { id: @id, authors: @authors, kinds: @kinds, since: @since, until: @until, limit: @limit, search: @search }.compact ('a'..'z').each do |char| var_value = instance_variable_get("@#{char}") result["##{char}"] = var_value unless var_value.nil? end ('A'..'Z').each do |char| var_value = instance_variable_get("@#{char}") result["##{char}"] = var_value unless var_value.nil? end result end |