Class: Cl::Arg
Constant Summary
Constants included from Cast
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#opts ⇒ Object
Returns the value of attribute opts.
Instance Method Summary collapse
- #define(const) ⇒ Object
- #description ⇒ Object
- #required? ⇒ Boolean
- #separator ⇒ Object
- #set(cmd, value) ⇒ Object
- #splat? ⇒ Boolean
- #to_s ⇒ Object
- #type ⇒ Object
Methods included from Cast
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name
4 5 6 |
# File 'lib/cl/arg.rb', line 4 def name @name end |
#opts ⇒ Object
Returns the value of attribute opts
4 5 6 |
# File 'lib/cl/arg.rb', line 4 def opts @opts end |
Instance Method Details
#define(const) ⇒ Object
7 8 9 |
# File 'lib/cl/arg.rb', line 7 def define(const) const.send(:attr_accessor, name) end |
#description ⇒ Object
19 20 21 |
# File 'lib/cl/arg.rb', line 19 def description opts[:description] end |
#required? ⇒ Boolean
23 24 25 |
# File 'lib/cl/arg.rb', line 23 def required? !!opts[:required] end |
#separator ⇒ Object
27 28 29 |
# File 'lib/cl/arg.rb', line 27 def separator opts[:sep] end |
#set(cmd, value) ⇒ Object
11 12 13 |
# File 'lib/cl/arg.rb', line 11 def set(cmd, value) cmd.send(:"#{name}=", cast(value)) end |
#splat? ⇒ Boolean
31 32 33 |
# File 'lib/cl/arg.rb', line 31 def splat? opts[:splat] && type == :array end |
#to_s ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cl/arg.rb', line 35 def to_s str = name case type when :array then str = "#{str}.." when :boolean, :bool then str = "#{str}:bool" when :integer, :int then str = "#{str}:int" when :float then str = "#{str}:float" end required? ? str : "[#{str}]" end |
#type ⇒ Object
15 16 17 |
# File 'lib/cl/arg.rb', line 15 def type opts[:type] || :string end |