Class: Jekyll::Compose::ArgParser

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-compose/arg_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args, options) ⇒ ArgParser

Returns a new instance of ArgParser.



5
6
7
8
9
# File 'lib/jekyll-compose/arg_parser.rb', line 5

def initialize(args, options)
  @args = args
  @options = options
  @config = Jekyll.configuration(options)
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



4
5
6
# File 'lib/jekyll-compose/arg_parser.rb', line 4

def args
  @args
end

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/jekyll-compose/arg_parser.rb', line 4

def config
  @config
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/jekyll-compose/arg_parser.rb', line 4

def options
  @options
end

Instance Method Details

#force?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/jekyll-compose/arg_parser.rb', line 27

def force?
  !!options["force"]
end

#layoutObject



19
20
21
# File 'lib/jekyll-compose/arg_parser.rb', line 19

def layout
  options["layout"] || Jekyll::Compose::DEFAULT_LAYOUT
end

#sourceObject



31
32
33
# File 'lib/jekyll-compose/arg_parser.rb', line 31

def source
  config["source"].gsub(%r!^#{Regexp.quote(Dir.pwd)}!, "")
end

#titleObject



23
24
25
# File 'lib/jekyll-compose/arg_parser.rb', line 23

def title
  args.join " "
end

#typeObject



15
16
17
# File 'lib/jekyll-compose/arg_parser.rb', line 15

def type
  options["extension"] || Jekyll::Compose::DEFAULT_TYPE
end

#validate!Object

Raises:

  • (ArgumentError)


11
12
13
# File 'lib/jekyll-compose/arg_parser.rb', line 11

def validate!
  raise ArgumentError, "You must specify a name." if args.empty?
end