class Microstation::TemplateInfo
Constants
- LIQUID_REGEXP
Attributes
drawing[R]
drawing_path[R]
locals[R]
placeholder_keys[R]
template[R]
Public Class Methods
new(drawing, tagset_filter: nil, tagset_map: faa_map, visible: false)
click to toggle source
# File lib/microstation/template_info.rb, line 25 def initialize(drawing, tagset_filter: nil, tagset_map: faa_map, visible: false) case drawing when ::Microstation::Drawing initialize_attributes(drawing) return when String,Pathname drawing_path = drawing else drawing_path = drawing.to_path end binding.pry ::Microstation::App.run(visible: visible) do |app| app.open_drawing(drawing_path) do |d| initialize_attributes(d) end end @tagset_filter = tagset_filter @tagset_map = tagset_map return self end
Public Instance Methods
before_locals(locals)
click to toggle source
# File lib/microstation/template_info.rb, line 84 def before_locals(locals) locals end
default_filter()
click to toggle source
# File lib/microstation/template_info.rb, line 80 def default_filter ->(ts){ ts.name == 'faatitle'} end
drawing_name()
click to toggle source
# File lib/microstation/template_info.rb, line 120 def drawing_name drawing_path.basename.to_s end
dump(dir = output_dir)
click to toggle source
# File lib/microstation/template_info.rb, line 128 def dump(dir = output_dir) dir = Pathname(dir) File.open(dir + yaml_filename, 'w'){|f| f.puts self.to_yaml} end
faa_map()
click to toggle source
# File lib/microstation/template_info.rb, line 102 def faa_map ->(ts){ if ts['tagset_name'] == 'faatitle' atts = ts['attributes'] new_atts = atts.keep_if{|k,v| faa_title_keys.include? k} ts['attributes']= new_atts ts else ts end } end
faa_title_keys()
click to toggle source
# File lib/microstation/template_info.rb, line 115 def faa_title_keys %w(microstation_id fac title1 title2 title3 subnam subttle appname appttl file dnnew jcnno city state) end
initialize_attributes(drawing)
click to toggle source
# File lib/microstation/template_info.rb, line 46 def initialize_attributes(drawing) @drawing_path = drawing.path entry_points = get_entry_points(drawing) @placeholder_keys = keys_from_entry_points(entry_points) @locals = keys_to_h(@placeholder_keys) @template = @drawing_path.to_s @tagsets = drawing_tagsets(drawing) @output_dir = output_dir(@drawing_path) end
output_dir(l_drawing_path = @drawing_path)
click to toggle source
# File lib/microstation/template_info.rb, line 61 def output_dir(l_drawing_path = @drawing_path) l_drawing_path.parent.to_s end
to_h()
click to toggle source
# File lib/microstation/template_info.rb, line 65 def to_h if tagset_filter filtered = tagsets.select{|ts| tagset_filter.call(ts)} else filtered = tagsets.dup end mapped_tsets = filtered.map{|ts| tagset_map.call(ts)} { template: template, output_dir: output_dir, name: drawing_name, locals: locals, tagsets: mapped_tsets } end
to_yaml()
click to toggle source
# File lib/microstation/template_info.rb, line 133 def to_yaml to_h.to_yaml end
yaml_filename()
click to toggle source
# File lib/microstation/template_info.rb, line 124 def yaml_filename drawing_path.basename.ext('yaml') end
Protected Instance Methods
entry_points(drawing)
click to toggle source
# File lib/microstation/template_info.rb, line 139 def entry_points(drawing) @entry_points ||= get_entry_points end
get_entry_points(drawing)
click to toggle source
# File lib/microstation/template_info.rb, line 143 def get_entry_points(drawing) result = [] drawing.scan_all_text do |m,text| binding.pry if text =~ /txt1/ result << [m, text.to_s] if text.to_s =~ /{{([^}}])+}}/ end binding.pry result end
keys_from_entry_points(entry_points= get_entry_points)
click to toggle source
# File lib/microstation/template_info.rb, line 154 def keys_from_entry_points(entry_points= get_entry_points) entry_points.reduce([]) do |result,(m,text)| text.scan(LIQUID_REGEXP).flatten.map{|t| t.strip}.each do |a| result << a end result.uniq end end
keys_to_h(keys= @placeholder_keys)
click to toggle source
# File lib/microstation/template_info.rb, line 163 def keys_to_h(keys= @placeholder_keys) keys.each_with_object({}) do |k,h| h[k] = "" end end