Class: Optitron::Dsl

Inherits:
Object
  • Object
show all
Defined in:
lib/optitron/dsl.rb

Defined Under Namespace

Classes: AbstractDsl, CmdParserDsl, RootParserDsl

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parser, &blk) ⇒ Dsl

Returns a new instance of Dsl.



5
6
7
8
9
10
11
# File 'lib/optitron/dsl.rb', line 5

def initialize(parser, &blk)
  @root = RootParserDsl.new(parser)
  if blk
    @root.configure_with(&blk)
    configure_options
  end
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



3
4
5
# File 'lib/optitron/dsl.rb', line 3

def root
  @root
end

Instance Method Details

#configure_optionsObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/optitron/dsl.rb', line 13

def configure_options
  @root.unclaimed_opts.each do |opt_option|
    name = opt_option.name
    if !@root.short_opts.key?(name[0].chr)
      opt_option.short_name = name[0].chr
      @root.short_opts[name[0].chr] = opt_option
    elsif !@root.short_opts.key?(name.upcase[0].chr)
      opt_option.short_name = name.upcase[0].chr
      @root.short_opts[name.upcase[0].chr] = opt_option
    end
  end
end