Class: V::Arguments::Slot

Inherits:
Object
  • Object
show all
Defined in:
lib/v/arguments.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argument, defaults, options) ⇒ Slot

Returns a new instance of Slot.



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/v/arguments.rb', line 70

def initialize(argument, defaults, options)
  @to_s, @to_sym = "#{ argument }".gsub('_', '-'), argument
  @captures = [argument]
  @options = options
  @standalone, @defaults = defaults.empty?, defaults.map { |d| d.to_s }

  @fstring = if @options[:rude] then '%s'
      elsif @options[:alias] and @standalone then '-$op'
      elsif @options[:alias] and not @standalone then '-$op %s'
      elsif not @options[:alias] and @standalone then '--$op'
      else '--$op=%s'
      end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym) ⇒ Object



83
84
85
86
# File 'lib/v/arguments.rb', line 83

def method_missing(sym)
  @captures << sym
  @to_s = sym.to_s if @options[:alias]
end

Instance Attribute Details

#to_symObject (readonly)

Returns the value of attribute to_sym.



69
70
71
# File 'lib/v/arguments.rb', line 69

def to_sym
  @to_sym
end

Instance Method Details

#defaults_to?(value) ⇒ Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/v/arguments.rb', line 93

def defaults_to?(value)
  @defaults.include? value.to_s
end

#key(opts) ⇒ Object



90
91
92
# File 'lib/v/arguments.rb', line 90

def key(opts)
  @captures.find { |cap| opts.member? cap }
end

#standalone?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/v/arguments.rb', line 87

def standalone?
  @standalone
end

#to_sObject



96
97
98
# File 'lib/v/arguments.rb', line 96

def to_s
  @fstring.sub '$op', @to_s
end