Class: DateLogic

Inherits:
BaseLogic show all
Defined in:
lib/cureutils/logic/date_logic.rb

Overview

Date class supports the precure format

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseLogic

#source_err, #source_input, #source_output

Constructor Details

#initializeDateLogic

Returns a new instance of DateLogic.



10
11
12
13
14
15
16
17
18
19
# File 'lib/cureutils/logic/date_logic.rb', line 10

def initialize
  super
  hashize_cure_date
  hashize_movie_date
  @in = []
  @in << nil
  @opt_date = false
  @opt_file = false
  @format = '+%F %H:%M:%S @P'
end

Instance Attribute Details

#format=(value) ⇒ Object (writeonly)

Sets the attribute format

Parameters:

  • value

    the value to set the attribute format to.



36
37
38
# File 'lib/cureutils/logic/date_logic.rb', line 36

def format=(value)
  @format = value
end

Instance Method Details

#opt_date(given_datetime) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/cureutils/logic/date_logic.rb', line 21

def opt_date(given_datetime)
  return if given_datetime.nil?

  @opt_date = true
  @in = []
  @in << given_datetime
end

#opt_file(filename) ⇒ Object



29
30
31
32
33
34
# File 'lib/cureutils/logic/date_logic.rb', line 29

def opt_file(filename)
  return if filename.nil?

  @opt_file = true
  source_input(filename)
end


38
39
40
41
42
43
44
45
46
47
# File 'lib/cureutils/logic/date_logic.rb', line 38

def print_results
  return 1 unless check_opts

  @in.each do |line|
    given_date = line ? natural_lang2time(line) : Time.now
    updated_fmt = update_fmt(given_date, @format) if given_date
    @out.puts given_date.strftime(updated_fmt) if updated_fmt
  end
  0
end