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.



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

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

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



2
3
4
# File 'lib/jekyll-compose/arg_parser.rb', line 2

def args
  @args
end

#configObject (readonly)

Returns the value of attribute config.



2
3
4
# File 'lib/jekyll-compose/arg_parser.rb', line 2

def config
  @config
end

#optionsObject (readonly)

Returns the value of attribute options.



2
3
4
# File 'lib/jekyll-compose/arg_parser.rb', line 2

def options
  @options
end

Instance Method Details

#force?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/jekyll-compose/arg_parser.rb', line 25

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

#layoutObject



17
18
19
# File 'lib/jekyll-compose/arg_parser.rb', line 17

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

#sourceObject



29
30
31
# File 'lib/jekyll-compose/arg_parser.rb', line 29

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

#titleObject



21
22
23
# File 'lib/jekyll-compose/arg_parser.rb', line 21

def title
  args.join " "
end

#typeObject



13
14
15
# File 'lib/jekyll-compose/arg_parser.rb', line 13

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

#validate!Object

Raises:

  • (ArgumentError)


9
10
11
# File 'lib/jekyll-compose/arg_parser.rb', line 9

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