class A14z6chElapsedDays::Cli

Public Instance Methods

between(from, to) click to toggle source
# File lib/a14z6ch_elapsed_days.rb, line 42
def between(from, to)
  begin
    puts "#{calc(from, to).to_s(:delimited)} days elapsed from the day \"#{from}\" to \"#{to}\".".colorize(:light_magenta)
  rescue ArgumentError => e
    if e.message.nil?
      puts "given date is not valid.".colorize(:light_blue)
    else
      puts e.message.colorize(:light_blue)
    end
  end
end
from(date) click to toggle source

calculating method @param from date

# File lib/a14z6ch_elapsed_days.rb, line 26
def from(date)
  begin
    puts "#{calc(date, Time.now.to_s).to_s(:delimited)} days elapsed from the day \"#{date}\" to NOW.".colorize(:light_magenta)
  rescue ArgumentError => e
    if e.message.nil?
      puts "given date is not valid.".colorize(:light_blue)
    else
      puts e.message.colorize(:light_blue)
    end
  end
end
version() click to toggle source
# File lib/a14z6ch_elapsed_days.rb, line 17
def version
  puts "a14z6ch appilication version : #{A14z6chElapsedDays::VERSION}"
end

Private Instance Methods

calc(from, to) click to toggle source
# File lib/a14z6ch_elapsed_days.rb, line 55
def calc(from, to)
  elapsed_seconds = Time.parse(to) - Time.parse(from)
  if elapsed_seconds < 0
    raise ArgumentError.new("TO DATE must be later than FROM DATE")
  else
    (elapsed_seconds / 60 / 60 / 24).to_i
  end
end