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.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/codinginfo.rb', line 70 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
159 160 161 162 163 164 165 |
# File 'lib/codinginfo.rb', line 159 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
151 152 153 |
# File 'lib/codinginfo.rb', line 151 def cvar_coded?(label) label.name.match?(CVAR_PREFIX_REGEXP) end |
#filter_list(list) ⇒ Object
145 146 147 148 149 |
# File 'lib/codinginfo.rb', line 145 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
138 139 140 141 142 143 |
# File 'lib/codinginfo.rb', line 138 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
155 156 157 |
# File 'lib/codinginfo.rb', line 155 def has_cvar_assignment?(label) @assignments.key?(label.name) end |
#headers_parsed?(row) ⇒ Boolean
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/codinginfo.rb', line 171 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
95 96 97 98 99 100 |
# File 'lib/codinginfo.rb', line 95 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
102 103 104 105 106 107 |
# File 'lib/codinginfo.rb', line 102 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
167 168 169 |
# File 'lib/codinginfo.rb', line 167 def remove_cvar_prefix(name) name.sub(CVAR_PREFIX_REGEXP, "") end |
#unflatten_list(list) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/codinginfo.rb', line 124 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
109 110 111 112 113 114 |
# File 'lib/codinginfo.rb', line 109 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 |