Class: MmTool::MmUserDefault
- Inherits:
-
Object
- Object
- MmTool::MmUserDefault
- Defined in:
- lib/mm_tool/mm_user_defaults.rb
Overview
A single user default.
Instance Attribute Summary collapse
-
#arg_format ⇒ Object
readonly
Returns the value of attribute arg_format.
-
#arg_long ⇒ Object
readonly
Returns the value of attribute arg_long.
-
#arg_short ⇒ Object
readonly
Returns the value of attribute arg_short.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#help_desc ⇒ Object
readonly
Returns the value of attribute help_desc.
-
#help_group ⇒ Object
readonly
Returns the value of attribute help_group.
-
#item_label ⇒ Object
readonly
Returns the value of attribute item_label.
-
#name ⇒ Object
readonly
———————————————————— Attributes ————————————————————.
Instance Method Summary collapse
-
#example_arg ⇒ Object
———————————————————— Utility: get an argument for output, aligning the short and long forms.
-
#initialize(key:, value:) ⇒ MmUserDefault
constructor
———————————————————— Initialize ————————————————————.
-
#value ⇒ Object
———————————————————— Value attribute accessors.
- #value=(value) ⇒ Object
- #value_printable ⇒ Object
-
#value_set? ⇒ Boolean
———————————————————— Indicates whether or not a value has been set.
Constructor Details
#initialize(key:, value:) ⇒ MmUserDefault
Initialize
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mm_tool/mm_user_defaults.rb', line 23 def initialize(key:, value:) @name = key @value = value[:value] @default = value[:default] @arg_short = value[:arg_short] @arg_long = value[:arg_long] @arg_format = value[:arg_format] @item_label = value[:item_label] @help_group = value[:help_group] @help_desc = value[:help_desc] @value_set = false end |
Instance Attribute Details
#arg_format ⇒ Object (readonly)
Returns the value of attribute arg_format.
15 16 17 |
# File 'lib/mm_tool/mm_user_defaults.rb', line 15 def arg_format @arg_format end |
#arg_long ⇒ Object (readonly)
Returns the value of attribute arg_long.
14 15 16 |
# File 'lib/mm_tool/mm_user_defaults.rb', line 14 def arg_long @arg_long end |
#arg_short ⇒ Object (readonly)
Returns the value of attribute arg_short.
13 14 15 |
# File 'lib/mm_tool/mm_user_defaults.rb', line 13 def arg_short @arg_short end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
12 13 14 |
# File 'lib/mm_tool/mm_user_defaults.rb', line 12 def default @default end |
#help_desc ⇒ Object (readonly)
Returns the value of attribute help_desc.
18 19 20 |
# File 'lib/mm_tool/mm_user_defaults.rb', line 18 def help_desc @help_desc end |
#help_group ⇒ Object (readonly)
Returns the value of attribute help_group.
17 18 19 |
# File 'lib/mm_tool/mm_user_defaults.rb', line 17 def help_group @help_group end |
#item_label ⇒ Object (readonly)
Returns the value of attribute item_label.
16 17 18 |
# File 'lib/mm_tool/mm_user_defaults.rb', line 16 def item_label @item_label end |
#name ⇒ Object (readonly)
Attributes
11 12 13 |
# File 'lib/mm_tool/mm_user_defaults.rb', line 11 def name @name end |
Instance Method Details
#example_arg ⇒ Object
Utility: get an argument for output, aligning the short
and long forms.
73 74 75 76 77 78 |
# File 'lib/mm_tool/mm_user_defaults.rb', line 73 def example_arg s = self.arg_short ? "#{self.arg_short}," : nil l = self.arg_format ? "#{self.arg_long} #{self.arg_format}" : "#{self.arg_long}" # " %-3s %s " % [s, l] "%-3s %s" % [s, l] end |
#value ⇒ Object
Value attribute accessors.
39 40 41 42 43 44 45 |
# File 'lib/mm_tool/mm_user_defaults.rb', line 39 def value if value_set? @value else @default end end |
#value=(value) ⇒ Object
47 48 49 50 |
# File 'lib/mm_tool/mm_user_defaults.rb', line 47 def value=(value) @value = value @value_set = true end |
#value_printable ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/mm_tool/mm_user_defaults.rb', line 52 def value_printable if self.value.instance_of?(Array) self.value.join(',') elsif [TrueClass, FalseClass].include?(self.value.class) self.value.human else self.value end end |
#value_set? ⇒ Boolean
Indicates whether or not a value has been set.
65 66 67 |
# File 'lib/mm_tool/mm_user_defaults.rb', line 65 def value_set? @value_set end |