Module: Lookbook::Utils
- Defined in:
- lib/lookbook/support/utils/utils.rb
Class Method Summary collapse
- .id(*args) ⇒ Object
- .name(str) ⇒ Object
- .symbolize_name(str) ⇒ Object
- .temp_id(prefix: nil) ⇒ Object
- .value_or_fallback(value, fallback = nil, &block) ⇒ Object
Class Method Details
.id(*args) ⇒ Object
4 5 6 7 8 |
# File 'lib/lookbook/support/utils/utils.rb', line 4 def id(*args) parts = args.map { |arg| arg.to_s } id_str = parts.join("-").force_encoding("UTF-8").parameterize.dasherize PathUtils.strip_slashes(id_str).tr("/", "-").gsub("--", "-") end |
.name(str) ⇒ Object
14 15 16 |
# File 'lib/lookbook/support/utils/utils.rb', line 14 def name(str) str.to_s.parameterize.tr("-", "_") end |
.symbolize_name(str) ⇒ Object
18 19 20 |
# File 'lib/lookbook/support/utils/utils.rb', line 18 def symbolize_name(str) name(str).to_sym end |
.temp_id(prefix: nil) ⇒ Object
10 11 12 |
# File 'lib/lookbook/support/utils/utils.rb', line 10 def temp_id(prefix: nil) [prefix, (Time.now.to_f * 1000).to_i + rand(0..100)].compact.join("-") end |
.value_or_fallback(value, fallback = nil, &block) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/lookbook/support/utils/utils.rb', line 22 def value_or_fallback(value, fallback = nil, &block) if value.nil? fallback_block = block || proc { fallback } fallback_block.call else value end end |