Skip to content
Browse files

refactor format method

  • Loading branch information...
1 parent 9359013 commit 94fdd2bafc6980b095af19e7fb23ff3889ecea4d @melborne committed Dec 20, 2010
Showing with 30 additions and 32 deletions.
  1. +2 −0 lib/calour/column.rb
  2. +28 −32 lib/calour/month.rb
View
2 lib/calour/column.rb
@@ -1,3 +1,5 @@
+# -*- encoding:utf-8 -*-
+
module Calour::ColumnForm
def three_columns_formatter(months, from, color)
out, year_label = [], nil
View
60 lib/calour/month.rb
@@ -29,15 +29,15 @@ def dates_by_block(from=0)
alias formaty format
def format(style=:block, from=0, color=false, footer=false)
- formatter = color ? color_proc : mono_proc
+ formatter = color ? method(:color_formatter) : method(:mono_formatter)
body =
case style
when :block
header(from, color, :block) +
- dates_by_block(from).map { |aweek| formatter[aweek] }
+ dates_by_block(from).map { |aweek| formatter.call aweek }
when :line
header(from, color, :line) +
- Array( formatter[dates] )
+ Array( formatter.call dates )
when :block3
months = [self-1, self, self+1]
three_columns_formatter(months, from, color)
@@ -91,35 +91,31 @@ def last_date(year, month, day=[28, 29, 30, 31])
Date.new(year, month, day.pop) rescue retry
end
- def mono_proc
- ->w{
- w.map do |d|
- str = "%2d"
- str = case d
- when neighbor? then str.replace " "
- else str
- end
- formaty str, d.day
- end.join(" ")
- }
- end
-
- def color_proc
- ->w{
- w.map do |d|
- str = "%2d"
- str = case d
- when neighbor?
- @colors[:neighbor] ? str.color(@colors[:neighbor]) : str.replace(" ")
- when holiday? then str.color(@colors[:holiday])
- when sunday? then str.color(@colors[:sunday])
- when saturday? then str.color(@colors[:saturday])
- else str
- end
- str = str.color(@colors[:today]) if today?[d]
- formaty str, d.day
- end.join(" ")
- }
+ def mono_formatter(dates)
+ dates.map do |d|
+ str = "%2d"
+ str = case d
+ when neighbor? then str.replace " "
+ else str
+ end
+ formaty str, d.day
+ end.join(" ")
+ end
+
+ def color_formatter(dates)
+ dates.map do |d|
+ str = "%2d"
+ str = case d
+ when neighbor?
+ @colors[:neighbor] ? str.color(@colors[:neighbor]) : str.replace(" ")
+ when holiday? then str.color(@colors[:holiday])
+ when sunday? then str.color(@colors[:sunday])
+ when saturday? then str.color(@colors[:saturday])
+ else str
+ end
+ str = str.color(@colors[:today]) if today?[d]
+ formaty str, d.day
+ end.join(" ")
end
def sunday?

0 comments on commit 94fdd2b

Please sign in to comment.
Something went wrong with that request. Please try again.