module Helpema::Piper::Refinements
Public Instance Methods
to_arg()
click to toggle source
# File lib/helpema/piper.rb, line 28 def to_arg Piper.to_arg(*self) end
to_args(usage:nil, synonyms:nil)
click to toggle source
# File lib/helpema/piper.rb, line 5 def to_args(usage:nil, synonyms:nil) # create separate args from self with the translated synonyms args = self.transform_keys(synonyms.to_h) # pad usage's defaults to args usage&.each{|key,default| args[key]=default unless args.has_key? key} # order might be important so enforce usage args = usage&.map{|k,v|[k,args[k]]} || args.to_a # convert key,value tuples to final list of args args.map!(&:to_arg) # get rid of nil args.compact! # ...and finally flatten! args.flatten! return args end
to_flag()
click to toggle source
# File lib/helpema/piper.rb, line 22 def to_flag return nil if self[-1].match?(/\d/) # like :arg0 (self.length > 1)? "--#{self}": "-#{self}" # like --verbose or -V end