Skip to content
Browse files

change some default settings

  • Loading branch information...
1 parent 0b4380f commit a72f058c0fc315d10be80414e462401a2eba6835 @melborne committed Dec 14, 2010
Showing with 22 additions and 26 deletions.
  1. +5 −6 bin/caline.rb
  2. +2 −2 lib/month.rb
  3. +15 −15 lib/year.rb
  4. +0 −3 test/tc_year.rb
View
11 bin/caline.rb
@@ -2,14 +2,13 @@
#-*-encoding: utf-8-*-
require_relative "../lib/month"
require_relative "../lib/year"
-require "termcolor"
year, mon = ARGV.map(&:to_i)
-unless mon
- year = year || Date.today.year
- cal = Caline::Year.new(year)
- puts cal.format
+if year && !mon
+ cal = Caline::Year.new(year, holidays: :ja_ja)
+ puts cal.color_format
else
cal = Caline::Month.new(year, mon)
- puts cal.format
+ cal.holidays = :ja_ja
+ puts cal.color_format
end
View
4 lib/month.rb
@@ -17,7 +17,7 @@ def initialize(year, month, colors={})
@first = Date.new(@year, @month, 1)
@last = last_date(@year, @month)
@colors = { year: :yellow, month: :green, today: [:green, :underline],
- saturday: :cyan, sunday: :magenta, holiday: :red, neighbor: :black }
+ saturday: :cyan, sunday: :magenta, holiday: :red, neighbor:nil }
@colors.update(colors)
@code = nil
end
@@ -108,7 +108,7 @@ def neighbor?
def today_format(str)
attrs = Array(@colors[:today])
- attrs.inject(str) { |s, color| s = s.send(color) }
+ attrs.inject(str) { |s, color| s.send(color) }
end
def header(from, color)
View
30 lib/year.rb
@@ -7,33 +7,28 @@ module Caline
class Year
@@holidays = Hash.new{ |h, k| h[k] = {} }
@@month_width = 20
- def initialize(year)
+ def initialize(year, opts={})
@year = year
- @months = (1..12).map { |m| Caline::Month.new(@year, m, neighbor: nil) }
+ @holidays = opts.delete(:holidays)
+ @months = (1..12).map { |m| Caline::Month.new(@year, m, opts) }
end
- def holidays=(code)
- @code = code
- @@holidays[@year][@code] ||= Caline::GCalendar.new(@year).holidays(@code)
- end
-
- def holidays
- @@holidays[@year]
- end
-
alias formaty format
def format(style=:week, from=0, color=false)
out = []
@months.each_slice(3) do |gr|
left, center, right = gr.map do |mon|
- mon.holidays=:ja_ja
- mon.color_format(:week, 0)[1..-1]
+ mon.holidays = @holidays if @holidays
+ mon.format(:week, 0, color)[1..-1]
end
left, center, right = align_size(left, center, right)
out << left.zip(center, right).map { |line| line.join(" ") }
end
- year_label = "#{@year}".center(@@month_width*3+4).yellow
- out.unshift year_label
+ out.unshift year_label(color)
+ end
+
+ def color_format(style=:week, from=0)
+ format(style, from, true)
end
private
@@ -47,6 +42,11 @@ def align_size(*args)
end
args
end
+
+ def year_label(color)
+ label = "#{@year}".center(@@month_width*3+4)
+ color ? label.yellow : label
+ end
end
end
View
3 test/tc_year.rb
@@ -6,9 +6,6 @@ class TestYear < Test::Unit::TestCase
def setup
@y2010 = Caline::Year.new(2010)
end
- def test_holidays
- @y2010.holidays = :ja_ja
- end
def test_format
puts @y2010.format

0 comments on commit a72f058

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