Class: Bricolage::DateParam

Inherits:
Param
  • Object
show all
Defined in:
lib/bricolage/parameters.rb

Instance Attribute Summary

Attributes inherited from Param

#arg_spec, #description, #name

Instance Method Summary collapse

Methods inherited from Param

#have_arg?, #inspect, #option_name, #optional?, #parse_option_value, #parse_value, #publish?, #required?

Constructor Details

#initialize(name, arg_spec, description, optional: false, publish: false) ⇒ DateParam

Returns a new instance of DateParam.



389
390
391
# File 'lib/bricolage/parameters.rb', line 389

def initialize(name, arg_spec, description, optional: false, publish: false)
  super name, arg_spec, description, optional: optional, publish: publish
end

Instance Method Details

#default_value(ctx, vars) ⇒ Object



393
394
395
# File 'lib/bricolage/parameters.rb', line 393

def default_value(ctx, vars)
  nil
end

#materialize(value, ctx, vars) ⇒ Object



397
398
399
400
401
402
403
404
405
406
407
408
409
410
# File 'lib/bricolage/parameters.rb', line 397

def materialize(value, ctx, vars)
  case value
  when Date
    value
  when String
    begin
      Date.parse(expand(value, vars))
    rescue ArgumentError
      raise ParameterError, "bad date format: #{value.inspect}"
    end
  else
    raise ParameterError, "unknown type for date parameter '#{name}': #{value.class}"
  end
end

#variables(date) ⇒ Object



412
413
414
415
# File 'lib/bricolage/parameters.rb', line 412

def variables(date)
  # "YYYY-MM-DD"
  wrap_variable_value(date.to_s)
end