Class: Aspera::Cli::ExtendedValue
- Inherits:
-
Object
- Object
- Aspera::Cli::ExtendedValue
- Includes:
- Singleton
- Defined in:
- lib/aspera/cli/extended_value.rb
Overview
command line extended values
Constant Summary collapse
- INIT =
special values
'INIT'- ALL =
'ALL'- DEF =
'DEF'
Class Method Summary collapse
- .assert_no_value(v, what) ⇒ Object
-
.decode_csvt(value) ⇒ Object
decode comma separated table text.
Instance Method Summary collapse
-
#evaluate(value) ⇒ Object
parse an option value if it is a String using supported extended value modifiers other value types are returned as is.
-
#evaluate_all(value) ⇒ Object
find inner extended values.
-
#ext_re ⇒ Object
Regex to match an extended value.
- #modifiers ⇒ Object
-
#set_handler(name, method) ⇒ Object
add a new handler.
Class Method Details
.assert_no_value(v, what) ⇒ Object
42 43 44 |
# File 'lib/aspera/cli/extended_value.rb', line 42 def assert_no_value(v, what) raise "no value allowed for extended value type: #{what}" unless v.empty? end |
.decode_csvt(value) ⇒ Object
decode comma separated table text
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/aspera/cli/extended_value.rb', line 27 def decode_csvt(value) col_titles = nil hash_array = [] CSV.parse(value).each do |values| next if values.empty? if col_titles.nil? col_titles = values else hash_array.push(col_titles.zip(values).to_h) end end Log.log.warn('Titled CSV file without any line') if hash_array.empty? return hash_array end |
Instance Method Details
#evaluate(value) ⇒ Object
parse an option value if it is a String using supported extended value modifiers other value types are returned as is
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/aspera/cli/extended_value.rb', line 92 def evaluate(value) return value unless value.is_a?(String) regex = Regexp.new("^#{ext_re}(.*)$") # first determine decoders, in reversed order handlers_reversed = [] while (m = value.match(regex)) handler = m[1].to_sym handlers_reversed.unshift(handler) value = m[2] # stop processing if handler is extend (it will be processed later) break if handler.eql?(:extend) end handlers_reversed.each do |handler| value = @handlers[handler].call(value) end return value end |
#evaluate_all(value) ⇒ Object
find inner extended values
111 112 113 114 115 116 117 118 119 |
# File 'lib/aspera/cli/extended_value.rb', line 111 def evaluate_all(value) regex = Regexp.new("^(.*)#{ext_re}([^@]*)@(.*)$") while (m = value.match(regex)) sub_value = "@#{m[2]}:#{m[3]}" Log.log.debug("evaluating #{sub_value}") value = m[1] + evaluate(sub_value) + m[4] end return value end |
#ext_re ⇒ Object
Regex to match an extended value
86 87 88 |
# File 'lib/aspera/cli/extended_value.rb', line 86 def ext_re "@(#{modifiers.join('|')}):" end |
#modifiers ⇒ Object
76 |
# File 'lib/aspera/cli/extended_value.rb', line 76 def modifiers; @handlers.keys; end |
#set_handler(name, method) ⇒ Object
add a new handler
79 80 81 82 83 |
# File 'lib/aspera/cli/extended_value.rb', line 79 def set_handler(name, method) Log.log.debug{"setting handler for #{name}"} Aspera.assert_type(name, Symbol){'name'} @handlers[name] = method end |