class SCSSBeautifier::Options

Attributes

options[R]

Public Class Methods

new() click to toggle source
# File lib/scss_beautifier/options.rb, line 8
def initialize
  @options = {}
  @option_parser = OptionParser.new do |opts|
    opts.version = SCSSBeautifier::VERSION
    add_banner(opts)
    add_config_option(opts)
    add_in_place_option(opts)
    add_generate_config_option(opts)
  end
end

Public Instance Methods

parse(args) click to toggle source
# File lib/scss_beautifier/options.rb, line 19
def parse(args)
  @option_parser.parse!(args)
  options[:path] = args.first if args.first
  add_defaults
  options
end

Private Instance Methods

add_banner(opts) click to toggle source
# File lib/scss_beautifier/options.rb, line 34
    def add_banner(opts)
      opts.banner = unindent(<<-BANNER)
        Beautify your SCSS code
        Usage: #{opts.program_name} [options] [path]
      BANNER
    end
add_config_option(opts) click to toggle source
# File lib/scss_beautifier/options.rb, line 41
def add_config_option(opts)
  message = "the configuration file"
  opts.on("-c", "--config config", message, String) do |config|
    self.options[:config] = config
  end
end
add_defaults() click to toggle source
# File lib/scss_beautifier/options.rb, line 28
def add_defaults
  if File.exists?(".scss-beautifier") && options[:config].nil?
    options[:config] = ".scss-beautifier"
  end
end
add_generate_config_option(opts) click to toggle source
# File lib/scss_beautifier/options.rb, line 55
def add_generate_config_option(opts)
  message = "generate a .scss-beautifier config with defaults"
  opts.on("-g", "--gen-config", message) do |bool|
    self.options[:generate_config] = bool
  end
end
add_in_place_option(opts) click to toggle source
# File lib/scss_beautifier/options.rb, line 48
def add_in_place_option(opts)
  message = "whether to overwrite the file or not"
  opts.on("-i", "--in-place", message) do |bool|
    self.options[:in_place] = bool
  end
end
unindent(str) click to toggle source
# File lib/scss_beautifier/options.rb, line 62
def unindent(str)
  str.gsub(/^#{str.scan(/^[ ]+(?=\S)/).min}/, "")
end