Class: Time

Inherits:
Object
  • Object
show all
Includes:
Runt
Defined in:
lib/runt.rb

Overview

Add the ability to use Time class

Contributed by Paul Wright

Constant Summary

Constants included from Runt

Runt::April, Runt::August, Runt::DAYS, Runt::December, Runt::Eighth, Runt::Eigth, Runt::February, Runt::Fifth, Runt::First, Runt::Fourth, Runt::Fri, Runt::Friday, Runt::January, Runt::July, Runt::June, Runt::Last, Runt::Last_of, Runt::MONTHS, Runt::March, Runt::May, Runt::Mon, Runt::Monday, Runt::Ninth, Runt::November, Runt::ORDINAL_ABBR, Runt::ORDINAL_SUFFIX, Runt::October, Runt::Sat, Runt::Saturday, Runt::Second, Runt::Second_to_last, Runt::September, Runt::Seventh, Runt::Sixth, Runt::Sun, Runt::Sunday, Runt::Tenth, Runt::Third, Runt::Thu, Runt::Thursday, Runt::Tue, Runt::Tuesday, Runt::VERSION, Runt::WEEK_OF_MONTH_ORDINALS, Runt::Wed, Runt::Wednesday

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Runt

#after, #before, const, day_name, format_date, format_time, #method_missing, month_name, ordinalize, #parse_time

Constructor Details

#initialize(*args) ⇒ Time

Returns a new instance of Time.



193
194
195
196
197
198
199
200
# File 'lib/runt.rb', line 193

def initialize(*args)
  if(args[0].instance_of?(Runt::DPrecision::Precision))
    @precision=args.shift
  else
    @precision=Runt::DPrecision::SEC
  end
  old_initialize(*args)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Runt

Instance Attribute Details

#date_precisionObject

Returns the value of attribute date_precision.



191
192
193
# File 'lib/runt.rb', line 191

def date_precision
  @date_precision
end

Class Method Details

.old_parseObject



212
# File 'lib/runt.rb', line 212

alias_method :old_parse, :parse

.parse(*args) ⇒ Object



213
214
215
216
217
218
219
220
221
# File 'lib/runt.rb', line 213

def parse(*args)
  precision=Runt::DPrecision::DEFAULT
  if(args[0].instance_of?(Runt::DPrecision::Precision))
    precision=args.shift
  end
  _parse=old_parse(*args)
  _parse.date_precision=precision
  _parse
end

Instance Method Details

#old_initializeObject



192
# File 'lib/runt.rb', line 192

alias_method :old_initialize, :initialize

#old_to_yamlObject



202
# File 'lib/runt.rb', line 202

alias :old_to_yaml :to_yaml

#to_yaml(options) ⇒ Object



203
204
205
206
207
208
209
# File 'lib/runt.rb', line 203

def to_yaml(options)
  if self.instance_variables.empty?
    self.old_to_yaml(options)
  else
    Time.old_parse(self.to_s).old_to_yaml(options)
  end
end