Class: Nyanko::Invoker::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/nyanko/invoker/options.rb

Constant Summary collapse

CANDIDATES =
{
  :active_if_options => true,
  :as                => true,
  :capture           => true,
  :locals            => true,
  :type              => true,
}

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Options

Returns a new instance of Options.



12
13
14
15
# File 'lib/nyanko/invoker/options.rb', line 12

def initialize(*args)
  @raw_options = args.extract_options!
  @args = args
end

Instance Method Details

#active_if_optionsObject



29
30
31
# File 'lib/nyanko/invoker/options.rb', line 29

def active_if_options
  options[:active_if_options] || {}
end

#asObject



33
34
35
# File 'lib/nyanko/invoker/options.rb', line 33

def as
  options[:as]
end

#captureObject



37
38
39
# File 'lib/nyanko/invoker/options.rb', line 37

def capture
  options.has_key?(:capture) ? capture[:capture] : true
end

#invoke_optionsObject



45
46
47
# File 'lib/nyanko/invoker/options.rb', line 45

def invoke_options
  { :capture => capture, :type => type }
end

#labelObject



21
22
23
# File 'lib/nyanko/invoker/options.rb', line 21

def label
  @args[1]
end

#localsObject



25
26
27
# File 'lib/nyanko/invoker/options.rb', line 25

def locals
  (options[:locals] || {}).symbolize_keys
end

#optionsObject



49
50
51
52
53
54
55
56
57
# File 'lib/nyanko/invoker/options.rb', line 49

def options
  @options ||= begin
    if short_hand_options?
      { :locals => @raw_options }
    else
      @raw_options
    end
  end
end

#short_hand_options?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/nyanko/invoker/options.rb', line 59

def short_hand_options?
  @raw_options.any? && @raw_options.keys.all? {|key| !CANDIDATES[key] }
end

#typeObject



41
42
43
# File 'lib/nyanko/invoker/options.rb', line 41

def type
  options[:type]
end

#unit_nameObject



17
18
19
# File 'lib/nyanko/invoker/options.rb', line 17

def unit_name
  @args[0]
end