Skip to content

Commit

Permalink
sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
hut committed Jul 17, 2009
1 parent 9b38cd6 commit a5fb43c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ Feature

(X) #0 09/07/17 colorful output in bf list
( ) #1 09/07/17 commands to shortest unambiguous string
( ) #2 09/07/17 sorting
(X) #2 09/07/17 sorting
(X) #3 09/07/17 have bugs at multiple categories
3 changes: 3 additions & 0 deletions bf
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ when 'refresh'
when 'less'
Please.list(arg1, true)

when 'sort'
Please.sort(arg1, arg2 == 'rev')

when /^(\d+)$/
if arg1
Please.modify( $1, sentence( 1..-1 ) )
Expand Down
24 changes: 24 additions & 0 deletions code/db.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,30 @@ def add(cat, task)
dump & ack
end

def sort(how, reverse=false)
load "sort"

if how == 'id'
sort_like { |a, b| a.id <=> b.id }
elsif how == 'alpha'
sort_like { |a, b| a.txt <=> b.txt }
elsif how == 'date'
sort_like { |a, b| a.time <=> b.time }
elsif how == 'open'
sort_like { |b, a| a.open.to_i <=> b.open.to_i }
end

dump & ack
end

def sort_like( &block )
for cat, bugs in @hash
bugs.sort! do |a, b|
block.call( a[1], b[1] )
end
end
end

def set_status(bug, open)
load open ? "open a bug" : "close a bug"

Expand Down
18 changes: 18 additions & 0 deletions code/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ def ensure_type(type, default)
end
end

class Hash
def sort!( &block )
replace( self.class[self.sort( &block )] )
end
end

class TrueClass
def to_i
1
end
end

class FalseClass
def to_i
0
end
end

class Fixnum
def spaces
' ' * self
Expand Down

0 comments on commit a5fb43c

Please sign in to comment.