Sha256: e05e479d20b46b632d2d7f4682792621ca7777633e05f25f26fc1481819b6d37
Contents?: true
Size: 825 Bytes
Versions: 5
Compression:
Stored size: 825 Bytes
Contents
module Docsplit module ArgumentParser # Flatten an options hash into an arguments string suitable for the command # line. def parse_options(opts) opts.map {|k, v| ["--#{k}", normalize_value(v)] }.flatten.join(' ') end # Normalize a value in an options hash for the command line. # Ranges look like: 1-10, Arrays like: 1,2,3. def normalize_value(value) case value when Range then normalize_range(value) when Array then value.map! {|v| v.is_a?(Range) ? normalize_range(v) : v }.join(',') else value.to_s end end # Serialize a Ruby range into it's command-line equivalent. def normalize_range(range) arr = range.to_a arr.empty? ? range.first.to_s : "#{range.first}-#{arr.last}" end end extend ArgumentParser end
Version data entries
5 entries across 5 versions & 1 rubygems