Class: NanDoc::OptsNormalizer::OptEnum
Instance Method Summary
collapse
#exclusive_opt_flags, #normalize_opt_key, #normalize_opts, #unnormalize_opt_key, #unnormalize_opt_keys
#basename_no_extension, #indent, #no_blank_lines, #no_leading_ws, #no_trailing_ws, #oxford_comma, #quoted, #reindent, #unindent
Constructor Details
#initialize(&block) ⇒ OptEnum
Returns a new instance of OptEnum.
96
97
98
|
# File 'lib/nandoc/support-modules.rb', line 96
def initialize(&block)
instance_eval(&block)
end
|
Instance Method Details
#command(cmd) ⇒ Object
99
100
101
|
# File 'lib/nandoc/support-modules.rb', line 99
def command cmd
@command = cmd
end
|
#default(str) ⇒ Object
102
103
104
|
# File 'lib/nandoc/support-modules.rb', line 102
def default str
@default = str
end
|
#name(name) ⇒ Object
105
106
107
|
# File 'lib/nandoc/support-modules.rb', line 105
def name name
@name = name
end
|
#parse(opts) ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/nandoc/support-modules.rb', line 108
def parse opts
found = nil
if opts.key?(@name)
v = opts[@name]
re = /\A#{Regexp.escape(v)}/
founds = @values.grep(re)
case founds.size
when 0; invalid(v)
when 1; found = founds.first
else found = founds.detect{|f| f==v} or too_many(founds)
end
elsif(@default)
found = @default
else
found = nil
end
opts[@name] = found if found found
end
|
#values(*v) ⇒ Object
127
128
129
130
|
# File 'lib/nandoc/support-modules.rb', line 127
def values *v
v = v.first if v.size==1 && Array === v
@values = v
end
|