Class: Codinginfo
Defined Under Namespace
Constant Summary collapse
- CVAR_PREFIX_REGEXP =
/^CVAR_[A-Za-z0-9_]+_\d+\./
- PARAM_ASSIGNMENT_HEADERS =
{ name: /Parameter/, cvar: /Schalter/, package: /Komponente/ }
Instance Method Summary collapse
- #add_cvar_prefix(name, variant) ⇒ Object
- #cvar_coded?(label) ⇒ Boolean
- #filter_list(list) ⇒ Object
- #flatten_list(list) ⇒ Object
- #has_cvar_assignment?(label) ⇒ Boolean
- #headers_parsed?(row) ⇒ Boolean
-
#initialize(filepath, filter) ⇒ Codinginfo
constructor
A new instance of Codinginfo.
- #overview_sheet ⇒ Object
- #param_assignment_sheet ⇒ Object
- #remove_cvar_prefix(name) ⇒ Object
- #unflatten_list(list) ⇒ Object
- #variant ⇒ Object
- #variants_description ⇒ Object
Constructor Details
#initialize(filepath, filter) ⇒ Codinginfo
Returns a new instance of Codinginfo.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/codinginfo.rb', line 69 def initialize(filepath, filter) @doc = SimpleXlsxReader.open(filepath) @filter = filter @headers = [] @variants = [] @assignments = {} overview_sheet .rows .each do |row| next unless headers_parsed?(row) next unless filter.match?(@headers, row) @variants << Variant.new(@headers, row) end param_assignment_sheet .rows .each(headers: PARAM_ASSIGNMENT_HEADERS) do |row| next if row[:cvar].nil? @assignments[row[:name]] = Cvar.new(name: row[:cvar], package: row[:package]) end end |
Instance Method Details
#add_cvar_prefix(name, variant) ⇒ Object
158 159 160 161 162 163 164 |
# File 'lib/codinginfo.rb', line 158 def add_cvar_prefix(name, variant) variant .cvars .find { _1 == @assignments[name] } .then { _1.combine(@assignments[name]) } .then { _1.label_prefix + name } end |
#cvar_coded?(label) ⇒ Boolean
150 151 152 |
# File 'lib/codinginfo.rb', line 150 def cvar_coded?(label) label.name.match?(CVAR_PREFIX_REGEXP) end |
#filter_list(list) ⇒ Object
144 145 146 147 148 |
# File 'lib/codinginfo.rb', line 144 def filter_list(list) list .select { |label| !cvar_coded?(label) || @variants.any? { _1.has_matching_cvar?(label) } } .with(headers: variants_description) end |
#flatten_list(list) ⇒ Object
137 138 139 140 141 142 |
# File 'lib/codinginfo.rb', line 137 def flatten_list(list) list .select { !cvar_coded?(_1) || variant.has_matching_cvar?(_1) } .map_int { _1.with(name: remove_cvar_prefix(_1.name)) } .with(headers: variants_description) end |
#has_cvar_assignment?(label) ⇒ Boolean
154 155 156 |
# File 'lib/codinginfo.rb', line 154 def has_cvar_assignment?(label) @assignments.key?(label.name) end |
#headers_parsed?(row) ⇒ Boolean
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/codinginfo.rb', line 170 def headers_parsed?(row) return true if @headers.any? return false unless row[1]&.match?(/SWFK-ID/) return false unless row[1]&.match?(/CVAR_BeguData/) return false unless row[2]&.match?(/Kommentar/) @headers = row .map(&:chomp) .map(&:lstrip) .map(&:strip) .map { _1.sub(/\n.*/, "") } .tap { _1[0] = :typestr } .tap { _1[1] = :swfk_id } .tap { _1[4] = :typekey } .tap { _1[6] = :devkey } end |
#overview_sheet ⇒ Object
94 95 96 97 98 99 |
# File 'lib/codinginfo.rb', line 94 def overview_sheet @doc .sheets .find { _1.name == "Gesamtübersicht" } .tap { fail "Cannot find sheet Gesamtübersicht" if _1.nil? } end |
#param_assignment_sheet ⇒ Object
101 102 103 104 105 106 |
# File 'lib/codinginfo.rb', line 101 def param_assignment_sheet @doc .sheets .find { _1.name == "Parameterdefinition" } .tap { fail "Cannot find sheet Parameterdefinition" if _1.nil? } end |
#remove_cvar_prefix(name) ⇒ Object
166 167 168 |
# File 'lib/codinginfo.rb', line 166 def remove_cvar_prefix(name) name.sub(CVAR_PREFIX_REGEXP, "") end |
#unflatten_list(list) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/codinginfo.rb', line 123 def unflatten_list(list) fail "No variants found matching #{@filter}" if @variants.empty? Ecu::LabelList.new \ list.flat_map { |label| if has_cvar_assignment?(label) @variants.map { label.with(name: add_cvar_prefix(label.name, _1)) } else label end }.uniq, variants_description end |
#variant ⇒ Object
108 109 110 111 112 113 |
# File 'lib/codinginfo.rb', line 108 def variant fail "No variant matching #{@filter} found!" if @variants.empty? fail "More than one variant matching #{@filter} found!" if @variants.size > 1 @variants.first end |