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'
- MARKER_START =
'@'
- MARKER_END =
':'
- MARKER_IN_END =
'@'
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
46 47 48 |
# File 'lib/aspera/cli/extended_value.rb', line 46 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
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/aspera/cli/extended_value.rb', line 31 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
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/aspera/cli/extended_value.rb', line 97 def evaluate(value) return value unless value.is_a?(String) regex = Regexp.new("^#{ext_re}(.*)$", Regexp::MULTILINE) # 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 Log.log.trace1{"evaluating: #{handlers_reversed}, value: #{value}"} handlers_reversed.each do |handler| value = @handlers[handler].call(value) end return value end |
#evaluate_all(value) ⇒ Object
find inner extended values
117 118 119 120 121 122 123 124 125 |
# File 'lib/aspera/cli/extended_value.rb', line 117 def evaluate_all(value) regex = Regexp.new("^(.*)#{ext_re}([^#{MARKER_IN_END}]*)#{MARKER_IN_END}(.*)$", Regexp::MULTILINE) 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
91 92 93 |
# File 'lib/aspera/cli/extended_value.rb', line 91 def ext_re "#{MARKER_START}(#{modifiers.join('|')})#{MARKER_END}" end |
#modifiers ⇒ Object
81 |
# File 'lib/aspera/cli/extended_value.rb', line 81 def modifiers; @handlers.keys; end |
#set_handler(name, method) ⇒ Object
add a new handler
84 85 86 87 88 |
# File 'lib/aspera/cli/extended_value.rb', line 84 def set_handler(name, method) Log.log.debug{"setting handler for #{name}"} Aspera.assert_type(name, Symbol){'name'} @handlers[name] = method end |