Module: Quando

Defined in:
lib/quando.rb,
lib/quando/config.rb,
lib/quando/parser.rb,
lib/quando/version.rb

Defined Under Namespace

Classes: Config, Parser

Constant Summary collapse

VERSION =
'0.0.6'

Class Method Summary collapse

Class Method Details

.configQuando::Config

Quando’s class-level configuration

Returns:



94
95
96
# File 'lib/quando/config.rb', line 94

def self.config
  @config ||= Config.new
end

.configure {|config| ... } ⇒ Quando::Config

Yields:

Returns:



99
100
101
102
103
# File 'lib/quando/config.rb', line 99

def self.configure
  config unless @config
  yield(config) if block_given?
  @config
end

.parse(date, opts = {}) ⇒ Date?

Parameters:

  • date (String)
  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :matcher (Regexp, Array<Regexp>) — default: nil
  • :century (Integer) — default: nil

Returns:

  • (Date, nil)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/quando.rb', line 15

def self.parse(date, opts = {})
  return if (date = date.to_s.strip).empty?

  p = Parser.new

  if opts[:matcher]
    p.configure do |c|
      c.formats = [opts[:matcher]].flatten
    end
  end

  if opts[:century]
    p.configure do |c|
      c.century = opts[:century]
    end
  end

  p.parse(date)
end

.reset!Quando::Config

Reset Quando’s class-level configuration to defaults

Returns:



107
108
109
# File 'lib/quando/config.rb', line 107

def self.reset!
  @config = Config.new
end