Class: Md2key::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/md2key/cli.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args) ⇒ Object (private)

Shorthand for ‘md2key convert *.md`



29
30
31
32
33
34
35
36
# File 'lib/md2key/cli.rb', line 29

def method_missing(*args)
  path = args.first.to_s
  if args.length == 1 && path.end_with?('.md')
    convert(path)
  else
    return super(*args)
  end
end

Instance Method Details

#convert(path) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/md2key/cli.rb', line 10

def convert(path)
  abort "md2key: `#{path}` does not exist" unless File.exist?(path)

  markdown = File.read(path)
  ast = Parser.new.parse(markdown)
  Converter.new.convert!(ast)
end

#initObject



20
21
22
23
24
# File 'lib/md2key/cli.rb', line 20

def init
  yaml = ConfigBuilder.build(skip_options: options[:skip_options])
  File.write('.md2key', yaml)
  puts "# Successfully generated .md2key!\n#{yaml}"
end