mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-02 19:05:32 -04:00
WIP
This commit is contained in:
parent
031ea7ef16
commit
748386f0af
@ -1,4 +1,5 @@
|
||||
require "uuid"
|
||||
require "big"
|
||||
|
||||
enum FilterType
|
||||
String
|
||||
@ -47,6 +48,23 @@ struct Filter
|
||||
_value.as_f32? || nil
|
||||
self.new key, value, type
|
||||
end
|
||||
|
||||
def match_chapter(obj : JSON::Any) : Bool
|
||||
raw_value = obj[key]
|
||||
case type
|
||||
when FilterType::String
|
||||
raw_value.as_s.lower == value.as_s.lower
|
||||
when FilterType::NumMin
|
||||
when FilterType::DateMin
|
||||
BigFloat.new(raw_value) >= BigFloat.new(value)
|
||||
when FilterType::NumMax
|
||||
when FilterType::DateMax
|
||||
BigFloat.new(raw_value) <= BigFloat.new(value)
|
||||
when FilterType::Array
|
||||
raw_value.as_s.lower.split(",")
|
||||
.map(&.strip).include? value.as_s.lower.strip
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
struct Subscription
|
||||
@ -65,6 +83,10 @@ struct Subscription
|
||||
@created_at = Time.utc.to_unix
|
||||
@last_checked = Time.utc.to_unix
|
||||
end
|
||||
|
||||
def match_chapter(obj : JSON::Any) : Bool
|
||||
filters.all? &.match_chapter(obj)
|
||||
end
|
||||
end
|
||||
|
||||
struct SubscriptionList
|
||||
|
Loading…
x
Reference in New Issue
Block a user