class Cigale::Exts
Public Instance Methods
asplode(node)
click to toggle source
Given `{“a” => “b”}`, returns [“a”, “b”]. Given `“a”`, returns [“a”, {}]
# File lib/cigale/exts.rb, line 24 def asplode(node) type = nil spec = {} case node when Hash type, spec = first_pair(node) when String type = node else raise "Invalid markup: #{node.inspect}" end return type, spec end
boolp(val, default)
click to toggle source
Give a default to a boolean parameter (val || default) doesn't work because val may be false instead of nil
# File lib/cigale/exts.rb, line 67 def boolp (val, default) if val.nil? default else val end end
dig(h, dotted_path)
click to toggle source
first_pair(h)
click to toggle source
Given {:a => b, :c => d, :e => f}, returns [:a, b]
# File lib/cigale/exts.rb, line 18 def first_pair(h) h.each_pair.next end
toa(input)
click to toggle source
Make sure something is an array
# File lib/cigale/exts.rb, line 41 def toa (input) case input when Array return input when nil return [] else return [input] end end
toh(input)
click to toggle source
Make sure something is a hash
# File lib/cigale/exts.rb, line 53 def toh (input) case input when Hash return input when nil return {} else raise "Can't toh {input.inspect}" end end