add bunch of methods

remove some debugging stuff
This commit is contained in:
Ward Wouts 2002-04-27 23:42:50 +00:00
parent b6f3ced015
commit 284c1f4308

View file

@ -166,7 +166,6 @@ def _insert(group, options)
when "alpha" when "alpha"
alpha(group) alpha(group)
when "before" when "before"
print "metsj\n"
before(group, arg) before(group, arg)
when "after" when "after"
after(group, arg) after(group, arg)
@ -178,7 +177,7 @@ end
def alpha (group) def alpha (group)
name = group["name"] name = group["name"]
for i in (0...@newsrc["list"].length) for i in (0...@newsrc["list"].length)
print @newsrc["list"][i]["name"],"\n" # print @newsrc["list"][i]["name"],"\n"
if ((name <=> @newsrc["list"][i]["name"]) == -1) if ((name <=> @newsrc["list"][i]["name"]) == -1)
# splice @$list, $i, 0, $group # splice @$list, $i, 0, $group
upper = @newsrc["list"].slice!(i..@newsrc["list"].length) upper = @newsrc["list"].slice!(i..@newsrc["list"].length)
@ -191,14 +190,14 @@ def alpha (group)
end end
def before(group, before) def before(group, before)
print "before\n" # print "before\n"
name = group["name"] name = group["name"]
for i in (0...@newsrc["list"].length) for i in (0...@newsrc["list"].length)
print @newsrc["list"][i]["name"],"\n" # print @newsrc["list"][i]["name"],"\n"
if (@newsrc["list"][i]["name"] == before.to_s) if (@newsrc["list"][i]["name"] == before.to_s)
print @newsrc["list"][i]["name"],"\n" # print @newsrc["list"][i]["name"],"\n"
upper = @newsrc["list"].slice!(i..@newsrc["list"].length) upper = @newsrc["list"].slice!(i..@newsrc["list"].length)
@newsrc["list"] += [ group ] @newsrc["list"] += [ group ]
@newsrc["list"] += upper @newsrc["list"] += upper
@ -215,7 +214,7 @@ def after(group, after)
for i in (0...@newsrc["list"].length) for i in (0...@newsrc["list"].length)
if (@newsrc["list"][i]["name"] == after.to_s) if (@newsrc["list"][i]["name"] == after.to_s)
print @newsrc["list"][i+1]["name"],"\n" #print @newsrc["list"][i+1]["name"],"\n"
upper = @newsrc["list"].slice!((i+1)..@newsrc["list"].length) upper = @newsrc["list"].slice!((i+1)..@newsrc["list"].length)
@newsrc["list"] += [ group ] @newsrc["list"] += [ group ]
@newsrc["list"] += upper @newsrc["list"] += upper
@ -261,6 +260,72 @@ def unsubscribe(name, options = {"where" => ""})
@newsrc["group"][name]["subscribed"] = false @newsrc["group"][name]["subscribed"] = false
end end
def mark(name, article, options = {"where" => ""})
unless @newsrc["group"].has_key?(name)
add_group(name, options)
end
@newsrc["group"][name]["articles"].insert(article)
end
def mark_list(name, list, options = {"where" => ""})
unless @newsrc["group"].has_key?(name)
add_group(name, options)
end
articles = @newsrc["group"][name]["articles"].union(list)
@newsrc["group"][name]["articles"] = articles
end
def mark_range(name, from, to, options = {"where" => ""})
unless @newsrc["group"].has_key?(name)
add_group(name, options)
end
range = Set::IntSpan.new("#{from}-#{to}")
articles = @newsrc["group"][name]["articles"].union(range)
@newsrc["group"][name]["articles"] = articles
end
def unmark(name, article, options = {"where" => ""})
unless @newsrc["group"].has_key?(name)
add_group(name, options)
end
@newsrc["group"][name]["articles"].remove(article)
end
def unmark_list(name, list, options = {"where" => ""})
unless @newsrc["group"].has_key?(name)
add_group(name, options)
end
articles = @newsrc["group"][name]["articles"].diff(list)
@newsrc["group"][name]["articles"] = articles
end
def unmark_range(name, from, to, options = {"where" => ""})
unless @newsrc["group"].has_key?(name)
add_group(name, options)
end
range = Set::IntSpan.new("#{from}-#{to}")
articles = @newsrc["group"][name]["articles"].diff(range)
@newsrc["group"][name]["articles"] = articles
end
def exists(name)
return @newsrc["group"].has_key?(name) ? true : false
end
def subscribed(name)
exists(name) and @newsrc["group"][name]["subscribed"]
end
def marked(name, article)
exists(name) and @newsrc["group"][name]["articles"].member(article)
end
def num_groups
return @newsrc["list"].length
end
end # class end # class
end # module end # module
@ -289,16 +354,16 @@ end # module
# [x] del_group # [x] del_group
# [x] subscribe # [x] subscribe
# [x] unsubscribe # [x] unsubscribe
# [ ] mark # [x] mark
# [ ] mark_list # [x] mark_list
# [ ] mark_range # [x] mark_range
# [ ] unmark # [x] unmark
# [ ] unmark_list # [x] unmark_list
# [ ] unmark_range # [x] unmark_range
# [ ] exists # [x] exists
# [ ] subscribed # [x] subscribed
# [ ] marked # [x] marked
# [ ] num_groups # [x] num_groups
# [ ] groups # [ ] groups
# [ ] sub_groups # [ ] sub_groups
# [ ] unsub_groups # [ ] unsub_groups