Class: Handlebars::Helpers::Comparison::Default
- Inherits:
-
BaseSafeStringHelper
- Object
- BaseHelper
- BaseSafeStringHelper
- Handlebars::Helpers::Comparison::Default
- Defined in:
- lib/handlebars/helpers/comparison/default.rb
Overview
Default: Returns the first value that is not nil or undefined, otherwise the ‘default’ value is returned.
Instance Method Summary collapse
- #handlebars_helper ⇒ Object
-
#parse(values) ⇒ String
Parse will Default: Returns the first value that is not nil or undefined, otherwise the ‘default’ value is returned.
Methods inherited from BaseSafeStringHelper
Methods inherited from BaseHelper
#parse_json, #struct_to_hash, #tokenizer, #wrapper
Instance Method Details
#handlebars_helper ⇒ Object
59 60 61 62 |
# File 'lib/handlebars/helpers/comparison/default.rb', line 59 def # Exclude last paramater which is the context V8::Object proc { |_context, *values| wrapper(parse(values[0..-2])) } end |
#parse(values) ⇒ String
Parse will Default: Returns the first value that is not nil or undefined, otherwise the ‘default’ value is returned.
51 52 53 54 55 56 57 |
# File 'lib/handlebars/helpers/comparison/default.rb', line 51 def parse(values) default_value = values[-1] find_value = values[0..-2].find { |value| !value.nil? } find_value || default_value end |