Class: L2meter::Configuration
- Inherits:
-
Object
- Object
- L2meter::Configuration
- Defined in:
- lib/l2meter/configuration.rb
Instance Attribute Summary collapse
-
#contexts ⇒ Object
readonly
Returns the value of attribute contexts.
- #output ⇒ Object
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
- #context(&block) ⇒ Object
- #context=(block_or_value) ⇒ Object
- #format_keys(&block) ⇒ Object
- #format_values(&block) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #key_formatter ⇒ Object
- #sort=(value) ⇒ Object
- #sort? ⇒ Boolean
- #value_formatter ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
7 8 9 |
# File 'lib/l2meter/configuration.rb', line 7 def initialize @contexts = [] end |
Instance Attribute Details
#contexts ⇒ Object (readonly)
Returns the value of attribute contexts.
5 6 7 |
# File 'lib/l2meter/configuration.rb', line 5 def contexts @contexts end |
#output ⇒ Object
11 12 13 |
# File 'lib/l2meter/configuration.rb', line 11 def output @output ||= $stdout end |
#prefix ⇒ Object
Returns the value of attribute prefix.
4 5 6 |
# File 'lib/l2meter/configuration.rb', line 4 def prefix @prefix end |
#source ⇒ Object
Returns the value of attribute source.
4 5 6 |
# File 'lib/l2meter/configuration.rb', line 4 def source @source end |
Instance Method Details
#context(&block) ⇒ Object
44 45 46 |
# File 'lib/l2meter/configuration.rb', line 44 def context(&block) @contexts = [block] end |
#context=(block_or_value) ⇒ Object
48 49 50 |
# File 'lib/l2meter/configuration.rb', line 48 def context=(block_or_value) @contexts = [block_or_value] end |
#format_keys(&block) ⇒ Object
21 22 23 |
# File 'lib/l2meter/configuration.rb', line 21 def format_keys(&block) @key_formatter = block end |
#format_values(&block) ⇒ Object
32 33 34 |
# File 'lib/l2meter/configuration.rb', line 32 def format_values(&block) @value_formatter = block end |
#key_formatter ⇒ Object
15 16 17 18 19 |
# File 'lib/l2meter/configuration.rb', line 15 def key_formatter @key_formatter ||= ->(key) do key.to_s.strip.downcase.gsub(/[^-a-z\d.#]+/, ?-) end end |
#sort=(value) ⇒ Object
40 41 42 |
# File 'lib/l2meter/configuration.rb', line 40 def sort=(value) @apply_sort = !!value end |
#sort? ⇒ Boolean
36 37 38 |
# File 'lib/l2meter/configuration.rb', line 36 def sort? defined?(@apply_sort) ? @apply_sort : false end |
#value_formatter ⇒ Object
25 26 27 28 29 30 |
# File 'lib/l2meter/configuration.rb', line 25 def value_formatter @value_formatter ||= ->(value) do value = value.to_s value =~ /\s/ ? value.inspect : value end end |