Module: Buda::Utils
- Defined in:
- lib/buda/utils.rb
Overview
A handful of run-of-the-mill utilities
Class Method Summary collapse
-
.flatten(sequences) ⇒ Object
Get a flat Array out of a list of lists of Iterables(Enumerators).
-
.pick(dict_, key) ⇒ Hash
If the key exists, you will get that key-value pair.
-
.pluralize(amount, noun, suffix = 's') ⇒ String
Get a pluralized noun with its appropiate quantifier.
-
.snake_to_pascal(name) ⇒ String
Transform a snake-cased name to its pascal-cased version.
Class Method Details
.flatten(sequences) ⇒ Object
Get a flat Array out of a list of lists of Iterables(Enumerators)
10 11 12 |
# File 'lib/buda/utils.rb', line 10 def flatten(sequences) Enumerator::Chain.new(*sequences).to_a end |
.pick(dict_, key) ⇒ Hash
If the key exists, you will get that key-value pair.
19 20 21 22 23 24 25 26 |
# File 'lib/buda/utils.rb', line 19 def pick(dict_, key) key = key.to_sym if dict_.key?(key) { "#{key}": dict_[key] } else {} end end |
.pluralize(amount, noun, suffix = 's') ⇒ String
Get a pluralized noun with its appropiate quantifier
34 35 36 37 |
# File 'lib/buda/utils.rb', line 34 def pluralize(amount, noun, suffix = 's') quantifier = amount or 'no' "#{quantifier} #{amount == 1 ? noun : noun + suffix}" end |
.snake_to_pascal(name) ⇒ String
Transform a snake-cased name to its pascal-cased version.
43 44 45 |
# File 'lib/buda/utils.rb', line 43 def snake_to_pascal(name) name.split('_').map(&:capitalize).join end |