class Wisepdf::Parser
Constants
- ESCAPED_OPTIONS
Public Class Methods
parse(options)
click to toggle source
# File lib/wisepdf/parser.rb, line 13 def parse(options) options = self.escape(options) options = self.flatten(options) parsed_options = {} options.each do |key, value| unless( value == false || value.nil? ) normalized_key = "--#{self.normalize_arg(key)}" parsed_options[normalized_key] = self.normalize_value(value) end end parsed_options end
Protected Class Methods
escape(options)
click to toggle source
# File lib/wisepdf/parser.rb, line 28 def escape(options) options.delete_if{ |k,v| ESCAPED_OPTIONS.include?(k.to_sym) } end
flatten(options, prefix = nil)
click to toggle source
# File lib/wisepdf/parser.rb, line 32 def flatten(options, prefix = nil) hash = {} options.each do |k,v| key = prefix.nil? ? k : "#{prefix.to_s}-#{k}" if v.is_a?(Hash) hash.delete(k) hash.merge!(self.flatten(v, key)) else hash[key.to_s] = v end end return hash end
normalize_arg(arg)
click to toggle source
# File lib/wisepdf/parser.rb, line 47 def normalize_arg(arg) arg.to_s.downcase.gsub(/[^a-z0-9]/,'-') end
normalize_value(value)
click to toggle source
# File lib/wisepdf/parser.rb, line 51 def normalize_value(value) case value when TrueClass nil else value.to_s end end