Class: Wabi::Variants::Definition
- Inherits:
-
Object
- Object
- Wabi::Variants::Definition
- Defined in:
- lib/wabi/variants.rb
Instance Method Summary collapse
- #base(str) ⇒ Object
-
#initialize ⇒ Definition
constructor
A new instance of Definition.
- #resolve(**opts) ⇒ Object
- #variant(key, options, default: nil) ⇒ Object
Constructor Details
#initialize ⇒ Definition
Returns a new instance of Definition.
26 27 28 29 30 |
# File 'lib/wabi/variants.rb', line 26 def initialize @base = "" @variants = {} @defaults = {} end |
Instance Method Details
#base(str) ⇒ Object
32 33 34 |
# File 'lib/wabi/variants.rb', line 32 def base(str) @base = str end |
#resolve(**opts) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/wabi/variants.rb', line 41 def resolve(**opts) parts = [@base] @variants.each do |key, | selected = opts[key] || @defaults[key] parts << [selected] if selected && [selected] end parts.compact.reject(&:empty?).join(" ") end |
#variant(key, options, default: nil) ⇒ Object
36 37 38 39 |
# File 'lib/wabi/variants.rb', line 36 def variant(key, , default: nil) @variants[key] = @defaults[key] = default if default end |