Class: MmTool::MmUserDefault

Inherits:
Object
  • Object
show all
Defined in:
lib/mm_tool/mm_user_defaults.rb

Overview

A single user default.

Instance Attribute Summary collapse

Instance Method Summary collapse

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_formatObject (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_longObject (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_shortObject (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

#defaultObject (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_descObject (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_groupObject (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_labelObject (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

#nameObject (readonly)


Attributes




11
12
13
# File 'lib/mm_tool/mm_user_defaults.rb', line 11

def name
  @name
end

Instance Method Details

#example_argObject


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

#valueObject


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_printableObject



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.


Returns:

  • (Boolean)


65
66
67
# File 'lib/mm_tool/mm_user_defaults.rb', line 65

def value_set?
  @value_set
end