Some more methods. When I get unmarked_articles working all

methods from the perl version I need are in. ;)
This commit is contained in:
Ward Wouts 2002-04-28 11:28:04 +00:00
parent 284c1f4308
commit 507adc9005

View file

@ -3,8 +3,6 @@
# $Id$
# $Source$
#
#################################
#
# newsrc.rb
# ported from Perl code by Ward Wouts
#
@ -124,7 +122,7 @@ def add_group(name, options)
del_group(name)
end
group = {"name" => name,
"subscribed" => 1,
"subscribed" => true,
"articles" => Set::IntSpan.new }
@newsrc["group"][name] = group
@ -324,7 +322,61 @@ def num_groups
return @newsrc["list"].length
end
def groups
list = @newsrc["list"]
list = list.collect{|x| x["name"]}
return list
end
def sub_groups
list = @newsrc["list"]
list = list.collect{|x| x["subscribed"] ? x["name"] : nil}
list.compact!
return list
end
def unsub_groups
list = @newsrc["list"]
list = list.collect{|x| x["subscribed"] ? nil : x["name"]}
list.compact!
return list
end
def marked_articles(name, options = {"where" => ""})
unless @newsrc["group"].has_key?(name)
add_group(name, options)
end
return @newsrc["group"][name]["articles"].elements
end
def unmarked_articles(name, from, to, options = {"where" => ""})
unless @newsrc["group"].has_key?(name)
add_group(name, options)
end
range = Set::IntSpan.new("#{from}-#{to}")
unmarked = range.diff(@newsrc["group"][name]["articles"])
return unmarked.elements
end
def get_articles(name, options = {"where" => ""})
unless @newsrc["group"].has_key?(name)
add_group(name, options)
end
@newsrc["group"][name]["articles"].run_list
end
def set_articles(name, articles, options = {"where" => ""})
Set::IntSpan.valid(articles) or return false
set = Set::IntSpan.new(articles)
set.finite or return false
min = set.min
min != nil and min < 0 and return false
unless @newsrc["group"].has_key?(name)
add_group(name, options)
end
@newsrc["group"][name]["articles"] = set
return true
end
end # class
@ -364,10 +416,10 @@ end # module
# [x] subscribed
# [x] marked
# [x] num_groups
# [ ] groups
# [ ] sub_groups
# [ ] unsub_groups
# [ ] marked_articles
# [x] groups
# [x] sub_groups
# [x] unsub_groups
# [x] marked_articles
# [ ] unmarked_articles
# [ ] get_articles
# [ ] set_articles
# [x] get_articles
# [x] set_articles