Class: Mcalendar::Command
- Inherits:
-
Object
- Object
- Mcalendar::Command
- Defined in:
- lib/mcalendar/command.rb
Class Method Summary collapse
Instance Method Summary collapse
- #day_of_weeks ⇒ Object
- #execute ⇒ Object
-
#how_many_days ⇒ Object
Number of days for each day of the week in this month.
-
#initialize(argv) ⇒ Command
constructor
A new instance of Command.
- #output_console ⇒ Object
- #output_holidays ⇒ Object
- #output_pdf ⇒ Object
- #pdf_filename ⇒ Object
Constructor Details
#initialize(argv) ⇒ Command
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/mcalendar/command.rb', line 9 def initialize(argv) # @argv = argv = Mcalendar::Options.new.parse(argv) @date = [:date] @console = [:console] @pdf = [:pdf] @pdf_name = [:name] @version = [:version] @holidays = [:holidays] @calendar = Mcalendar::Calendar.new(@date.year, @date.month) @schedule = Mcalendar::Schedule.new(@calendar, ) @wday = [:wday] end |
Class Method Details
.run(argv) ⇒ Object
5 6 7 |
# File 'lib/mcalendar/command.rb', line 5 def self.run(argv) new(argv).execute end |
Instance Method Details
#day_of_weeks ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/mcalendar/command.rb', line 41 def day_of_weeks wks = @calendar.days.each_slice(7).map(&:to_a) keys = Mcalendar::DAY_OF_WEEK.map(&:downcase).map(&:to_sym) vals = (0..6).map do |wd| w = wks.map {|wk| wk[wd]} w.delete(" ") w.compact end Hash[keys.zip(vals)] end |
#execute ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/mcalendar/command.rb', line 74 def execute # output calendar output_console if @console output_pdf if @pdf output_holidays if @holidays # both outputs if no options if @console.nil? && @pdf.nil? && @version.nil? && @holidays.nil? && @wday.nil? output_console output_pdf end # Number of days for each day of the week in this month. how_many_days if @wday end |
#how_many_days ⇒ Object
Number of days for each day of the week in this month.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mcalendar/command.rb', line 29 def how_many_days wdays = Mcalendar::DAY_OF_WEEK.map {|w| w.capitalize + "."} wvalues = day_of_weeks.values puts "\nNumber of days for each day of the week in #{@date.strftime("%B %Y")}" puts "------------------------------------------------------------" wdays.each_with_index do |wday, idx| puts "#{wday} #{wvalues[idx].size} days. => #{wvalues[idx].join(",")}" end end |
#output_console ⇒ Object
24 25 26 |
# File 'lib/mcalendar/command.rb', line 24 def output_console puts @calendar.to_s end |
#output_holidays ⇒ Object
59 60 61 62 63 64 |
# File 'lib/mcalendar/command.rb', line 59 def output_holidays puts "=========== Holidays ===========" puts @schedule.show_holidays puts "======== Anniversaries =========" puts @schedule.show_anniversaries end |
#output_pdf ⇒ Object
54 55 56 57 |
# File 'lib/mcalendar/command.rb', line 54 def output_pdf outputpdf = Mcalendar::OutputPdf.new(@calendar, @schedule) outputpdf.render_file(pdf_filename) end |
#pdf_filename ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/mcalendar/command.rb', line 66 def pdf_filename if @pdf_name.nil? || @pdf_name.empty? Mcalendar::DEFAULT_PDF_NAME else @pdf_name = @pdf_name.downcase.end_with?(".pdf")? @pdf_name : @pdf_name + ".pdf" end end |