Class: PaymentDay::View
- Inherits:
-
Object
- Object
- PaymentDay::View
- Defined in:
- lib/payment_day.rb
Overview
View class
Constant Summary collapse
- DEFAULT_OPTIONS =
{ ascii: false, colors: true, columns: 10, dayname: true, duplicates: false, footer: true, page: 1, pages: 1, separator: true }.freeze
Instance Attribute Summary collapse
-
#pay_days ⇒ Object
readonly
Returns the value of attribute pay_days.
-
#years ⇒ Object
readonly
Returns the value of attribute years.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*years) ⇒ View
constructor
A new instance of View.
- #list ⇒ Object (also: #show)
Constructor Details
#initialize(*years) ⇒ View
Returns a new instance of View.
27 28 29 30 31 32 33 |
# File 'lib/payment_day.rb', line 27 def initialize(*years) = years.last.is_a?(Hash) ? years.slice!(-1) : {} @months = [] @options = DEFAULT_OPTIONS.merge .transform_keys(&:to_sym) @years = prepare_years(years) @pay_days = find_pay_days end |
Instance Attribute Details
#pay_days ⇒ Object (readonly)
Returns the value of attribute pay_days.
25 26 27 |
# File 'lib/payment_day.rb', line 25 def pay_days @pay_days end |
#years ⇒ Object (readonly)
Returns the value of attribute years.
25 26 27 |
# File 'lib/payment_day.rb', line 25 def years @years end |
Class Method Details
.create(*years) ⇒ Object
35 36 37 |
# File 'lib/payment_day.rb', line 35 def self.create(*years) new(*years) end |
Instance Method Details
#list ⇒ Object Also known as: show
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/payment_day.rb', line 39 def list Terminal::Table.new do |t| t.title = format("Pay days", :bright) t.headings = [format("Month", :bright)] + @years.map do |y| { value: format(y, :bright), alignment: :center } end t.style = { all_separators: @options[:separator], border: border } t.rows = @months.map { |m| format(m, :cyan) }.zip(*format_pay_days) @years.each_index { |v| t.align_column v.next, :center } page = @options[:page] pages = @options[:pages] if @options[:footer] && pages > 1 t.add_row [{ colspan: @years.length.next, value: "Page #{page}/#{pages}", alignment: :center }] end end end |