Class: Bricolage::DateParam
Instance Attribute Summary
Attributes inherited from Param
#arg_spec, #description, #name
Instance Method Summary collapse
- #default_value(ctx, vars) ⇒ Object
-
#initialize(name, arg_spec, description, optional: false, publish: false) ⇒ DateParam
constructor
A new instance of DateParam.
- #materialize(value, ctx, vars) ⇒ Object
- #variables(date) ⇒ Object
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((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 |