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
-
#initialize(filepath, filter, nocache: false) ⇒ Codinginfo
constructor
A new instance of Codinginfo.
- #remove_cvar_prefix(name) ⇒ Object
- #unflatten_list(list) ⇒ Object
- #variant ⇒ Object
- #variants_description ⇒ Object
Constructor Details
#initialize(filepath, filter, nocache: false) ⇒ Codinginfo
Returns a new instance of Codinginfo.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/codinginfo.rb', line 77 def initialize(filepath, filter, nocache: false) @filter = filter @variants = [] parsed = nocache ? parse_xlsx(filepath) : FileCache.get(filepath) { parse_xlsx(filepath) } @headers = parsed[:headers] @assignments = parsed[:assignments] parsed[:rows].each do |row| next unless filter.match?(@headers, row) @variants << Variant.new(@headers, row) end end |
Instance Method Details
#add_cvar_prefix(name, variant) ⇒ Object
143 144 145 146 147 148 149 |
# File 'lib/codinginfo.rb', line 143 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
135 136 137 |
# File 'lib/codinginfo.rb', line 135 def cvar_coded?(label) label.name.match?(CVAR_PREFIX_REGEXP) end |
#filter_list(list) ⇒ Object
129 130 131 132 133 |
# File 'lib/codinginfo.rb', line 129 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
122 123 124 125 126 127 |
# File 'lib/codinginfo.rb', line 122 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
139 140 141 |
# File 'lib/codinginfo.rb', line 139 def has_cvar_assignment?(label) @assignments.key?(label.name) end |
#remove_cvar_prefix(name) ⇒ Object
151 152 153 |
# File 'lib/codinginfo.rb', line 151 def remove_cvar_prefix(name) name.sub(CVAR_PREFIX_REGEXP, "") end |
#unflatten_list(list) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/codinginfo.rb', line 108 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
93 94 95 96 97 98 |
# File 'lib/codinginfo.rb', line 93 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 |