Class: FoggyMirror::CLI
- Inherits:
-
Object
- Object
- FoggyMirror::CLI
- Defined in:
- lib/foggy-mirror/cli.rb
Constant Summary collapse
- DEFAULT_EXTENSION =
'.foggy.svg'
- DEFAULT_FORMAT =
:svg
- FORMATS =
%i[svg css]
Instance Method Summary collapse
-
#initialize(args = ARGV) ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
Constructor Details
#initialize(args = ARGV) ⇒ CLI
Returns a new instance of CLI.
12 13 14 |
# File 'lib/foggy-mirror/cli.rb', line 12 def initialize(args = ARGV) @args = args.dup end |
Instance Method Details
#run ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/foggy-mirror/cli.rb', line 16 def run @options = {} @extension = DEFAULT_EXTENSION @format = DEFAULT_FORMAT @strategy = SVG::STRATEGIES.first @stdout = false @target_dir = nil parser.parse!(@args) # OptionParser.parse removes options from the args, so we're left with # filenames @args.each do |path| p = Processor.new(path, **@options) output = case @format when :svg p.to_svg(strategy: @strategy) when :css @stdout = true p.to_css end if @stdout puts output else foggy_file = File.join(@target_dir || File.dirname(path), File.basename(path, '.*') + @extension) IO.write(foggy_file, output) end end end |