Class: DateLogic
- Defined in:
- lib/cureutils/logic/date_logic.rb
Overview
Date class supports the precure format
Instance Attribute Summary collapse
-
#format ⇒ Object
writeonly
Sets the attribute format.
Instance Method Summary collapse
-
#initialize ⇒ DateLogic
constructor
A new instance of DateLogic.
- #opt_date(given_datetime) ⇒ Object
- #opt_file(filename) ⇒ Object
- #print_results ⇒ Object
Methods inherited from BaseLogic
#source_err, #source_input, #source_output
Constructor Details
#initialize ⇒ DateLogic
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
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 |
#print_results ⇒ Object
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 |