Class: AutoColors::Mapping
- Inherits:
-
Object
- Object
- AutoColors::Mapping
- Defined in:
- lib/autocolors/mapping.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
Returns the value of attribute entries.
Instance Method Summary collapse
-
#initialize ⇒ Mapping
constructor
A new instance of Mapping.
- #parse_map(lines) ⇒ Object
- #parse_values ⇒ Object
Constructor Details
#initialize ⇒ Mapping
Returns a new instance of Mapping.
26 27 28 29 30 |
# File 'lib/autocolors/mapping.rb', line 26 def initialize map_name = File.dirname(__FILE__) + '/mapping.udon' @entries = {} parse_map(IO.readlines(map_name)) end |
Instance Attribute Details
#entries ⇒ Object
Returns the value of attribute entries.
25 26 27 |
# File 'lib/autocolors/mapping.rb', line 25 def entries @entries end |
Instance Method Details
#parse_map(lines) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/autocolors/mapping.rb', line 32 def parse_map(lines) lines.each_with_index do |row,i| cols = row.gsub(/#.*/,'').strip.split(/\|/u).map{|c| c.strip} next if cols.size == 0 if cols.size < 13 $stderr.puts("Warning - incomplete mapping line #{i+1} of mapping.udon.") next end cols.shift # blank from leading pipe name = cols.shift @entries[name] = MapEntry.new(name, Hash[*KEYS.zip(cols).flatten]) end parse_values end |
#parse_values ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/autocolors/mapping.rb', line 47 def parse_values @entries.each do |name, entry| name_parts = name.split('.') if name_parts.size > 1 localpart = name_parts.pop parent_key = name_parts.join('.') if ! @entries.has_key?(parent_key) $stderr.puts("Warning - skipping entry #{name} because #{parent_key} not found.") @entries.delete(name) next end entry.parent = @entries[parent_key] entry.parent.children << entry end end end |