/
cal copy
executable file
·112 lines (98 loc) · 2.65 KB
/
cal copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env ruby
$LOAD_PATH << "lib"
require 'zeller'
require 'assemble_month'
require 'print_cal'
#Calendar is called at end of file
class Calendar
attr_accessor :month
attr_accessor :year
attr_accessor :calendar
attr_accessor :rows
attr_accessor :format_array
def initialize(*args)
input = args[0]
@months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
#current month (no input)
if input.length == 0
time = Time.new
@month = time.month
@year = time.year
self.zeller(@month, @year, false)
#unspecified number of rows
elsif input.length == 1
year = input[0].dup
@month = "annual"
@rows = 4
year.chomp!
@year = year.to_i
@calendar = []
@format_array = [[4, 3]]
self.annual(@year)
#specified number of rows
elsif input.length > 2
if input.length == 3 && input[1] == "rows"
rows = input[2].dup
@rows = rows.to_i
#even number of rows
if @rows == 2 || @rows == 3 || @rows ==4 || @rows == 6 || @rows == 12
year = input[0].dup
@month = "annual"
year.chomp!
@year = year.to_i
columns = 12/@rows
@calendar = []
@format_array = [[@rows, columns]]
self.annual(@year)
#bad row argument
elsif @rows < 2 || @rows > 12
puts "INPUT ERROR"
puts "Number of rows must be between 2 and 12"
#5 rows
else
if @rows == 5
year = input[0].dup
@month = "annual"
year.chomp!
@year = year.to_i
@format_array = [[3, 3], [1, 2], [1, 1]]
@calendar = []
self.annual(@year)
#7-11 rows
else
year = input[0].dup
@month = "annual"
year.chomp!
@year = year.to_i
temp_rows = 12 % @rows
extra_rows = @rows - (12 % @rows)
@rows = temp_rows
@format_array = [[@rows, 2], [@extra_rows, 1]]
@calendar = []
self.annual(@year)
end
end
#bad input
else
puts "INPUT ERROR"
puts "Accepted Format is: 2014, 01 2014, January 2014, or 2014 rows 2"
end
#single month
else
month = input[0].dup
year = input[1].dup
month.chomp!
@month = month
year.chomp!
@year = year.to_i
self.zeller(@month, @year, false)
end
end #of initialize
def annual(year)
month = 0
12.times do
month += 1
self.zeller(month, year, true)
end
end
end