module Pdfh
Gem entry point
Constants
- DocumentSubType
- DocumentType
- OPT_PARSER
- SETTINGS_TEMPLATE
rubocop:disable Layout/HashAlignment
- VERSION
Attributes
dry[W]
verbose[W]
Public Class Methods
config_file_name()
click to toggle source
@return [String]
# File lib/pdfh.rb, line 102 def config_file_name File.basename($PROGRAM_NAME) end
console_size()
click to toggle source
Returns rows, cols TODO: review gist.github.com/nixpulvis/6025433 @return [Array<Integer, Integer>]
# File lib/pdfh.rb, line 45 def console_size `stty size`.split.map(&:to_i) end
create_settings_file()
click to toggle source
@return [void]
# File lib/pdfh.rb, line 107 def create_settings_file full_path = File.join(File.expand_path("~"), "#{config_file_name}.yml") return if File.exist?(full_path) # double check File.open(full_path, "w") do |f| f.write Pdfh::SETTINGS_TEMPLATE.to_yaml end puts "Settings #{full_path.inspect.colorize(:green)} was created." end
dry?()
click to toggle source
@return [Boolean]
# File lib/pdfh.rb, line 38 def dry? @dry end
error_print(message, exit_app: true)
click to toggle source
@param message [String] @param exit_app [Boolean] exit application if true (default) @return [void]
# File lib/pdfh.rb, line 71 def error_print(message, exit_app: true) puts "Error, #{message}".colorize(:red) exit 1 if exit_app end
headline(msg)
click to toggle source
Prints visual separator in shell for easier reading for humans @example output
[Title Text] -----------------------
@param msg [String] @return [void]
# File lib/pdfh.rb, line 54 def headline(msg) _, cols = console_size line_length = cols - (msg.size + 5) left = "\033[31m#{"—" * 3}\033[0m" right = "\033[31m#{"—" * line_length}\033[0m" puts "\n#{left} \033[1;34m#{msg}\033[0m #{right}" end
ident_print(field, value, color: :green, width: 3)
click to toggle source
@return [void]
# File lib/pdfh.rb, line 83 def ident_print(field, value, color: :green, width: 3) field_str = field.to_s.rjust(width) value_str = value.colorize(color) puts "#{" " * 4}#{field_str}: #{value_str}" end
parse_argv()
click to toggle source
@return [Hash]
# File lib/pdfh.rb, line 90 def parse_argv options = {} OPT_PARSER.parse!(into: options) options[:files] = ARGV if ARGV.any? options.transform_keys { |key| key.to_s.tr("-", "_").to_sym } rescue OptionParser::InvalidOption => e error_print e.message, exit_app: false puts OPT_PARSER.help exit 1 end
search_config_file()
click to toggle source
@raise [SettingsIOError] if no file is found @return [String]
# File lib/pdfh.rb, line 119 def search_config_file names_to_look = %W[#{config_file_name}.yml #{config_file_name}.yaml] dir_order = [Dir.pwd, File.expand_path("~")] dir_order.each do |dir| names_to_look.each do |file| path = File.join(dir, file) return path if File.exist?(path) end end raise SettingsIOError, "no configuration file (#{names_to_look.join(" or ")}) was found\n"\ " within paths: #{dir_order.join(", ")}" end
verbose?()
click to toggle source
@return [Boolean]
# File lib/pdfh.rb, line 33 def verbose? @verbose end
verbose_print(msg = nil)
click to toggle source
@param msg [Object] @return [void]
# File lib/pdfh.rb, line 64 def verbose_print(msg = nil) puts msg.to_s.colorize(:cyan) if verbose? end
warn_print(message)
click to toggle source
@param message [String] @return [void]
# File lib/pdfh.rb, line 78 def warn_print(message) puts message.colorize(:yellow) end