Class: Microstation::TemplateInfo
- Inherits:
-
Object
- Object
- Microstation::TemplateInfo
- Defined in:
- lib/microstation/template_info.rb
Defined Under Namespace
Classes: TagSetMap
Constant Summary collapse
- LIQUID_REGEXP =
/{{([^}}]+)}}/
Instance Attribute Summary collapse
-
#drawing ⇒ Object
readonly
Returns the value of attribute drawing.
-
#drawing_path ⇒ Object
readonly
Returns the value of attribute drawing_path.
-
#locals ⇒ Object
readonly
Returns the value of attribute locals.
-
#placeholder_keys ⇒ Object
readonly
Returns the value of attribute placeholder_keys.
-
#tagset_filter ⇒ Object
readonly
Returns the value of attribute tagset_filter.
-
#tagset_map ⇒ Object
readonly
Returns the value of attribute tagset_map.
-
#tagsets ⇒ Object
readonly
Returns the value of attribute tagsets.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
- #before_locals(locals) ⇒ Object
- #default_filter ⇒ Object
- #do_tagset_mappings ⇒ Object
- #drawing_name ⇒ Object
- #drawing_tagsets(drawing) ⇒ Object
- #dump(dir = output_dir) ⇒ Object
- #faa_map ⇒ Object
- #faa_title_keys ⇒ Object
-
#initialize(drawing, tagset_filter: nil, tagset_map: faa_map, visible: false) ⇒ TemplateInfo
constructor
A new instance of TemplateInfo.
- #initialize_attributes(drawing) ⇒ Object
- #map_tagset(mapname:, filter: tagset_name_filter, &block) ⇒ Object
- #output_dir(l_drawing_path = @drawing_path) ⇒ Object
- #to_h ⇒ Object
- #to_yaml ⇒ Object
- #yaml_filename ⇒ Object
Constructor Details
#initialize(drawing, tagset_filter: nil, tagset_map: faa_map, visible: false) ⇒ TemplateInfo
Returns a new instance of TemplateInfo.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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_map = return self end |
Instance Attribute Details
#drawing ⇒ Object (readonly)
Returns the value of attribute drawing.
23 24 25 |
# File 'lib/microstation/template_info.rb', line 23 def drawing @drawing end |
#drawing_path ⇒ Object (readonly)
Returns the value of attribute drawing_path.
23 24 25 |
# File 'lib/microstation/template_info.rb', line 23 def drawing_path @drawing_path end |
#locals ⇒ Object (readonly)
Returns the value of attribute locals.
23 24 25 |
# File 'lib/microstation/template_info.rb', line 23 def locals @locals end |
#placeholder_keys ⇒ Object (readonly)
Returns the value of attribute placeholder_keys.
23 24 25 |
# File 'lib/microstation/template_info.rb', line 23 def placeholder_keys @placeholder_keys end |
#tagset_filter ⇒ Object (readonly)
Returns the value of attribute tagset_filter.
23 24 25 |
# File 'lib/microstation/template_info.rb', line 23 def @tagset_filter end |
#tagset_map ⇒ Object (readonly)
Returns the value of attribute tagset_map.
23 24 25 |
# File 'lib/microstation/template_info.rb', line 23 def @tagset_map end |
#tagsets ⇒ Object (readonly)
Returns the value of attribute tagsets.
23 24 25 |
# File 'lib/microstation/template_info.rb', line 23 def @tagsets end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
23 24 25 |
# File 'lib/microstation/template_info.rb', line 23 def template @template end |
Instance Method Details
#before_locals(locals) ⇒ Object
84 85 86 |
# File 'lib/microstation/template_info.rb', line 84 def before_locals(locals) locals end |
#default_filter ⇒ Object
80 81 82 |
# File 'lib/microstation/template_info.rb', line 80 def default_filter ->(ts){ ts.name == 'faatitle'} end |
#do_tagset_mappings ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/microstation/template_info.rb', line 92 def @tagset_mappings.each do |ts_mapper| ts_mapper.call() ti_instances = .select{|ts| ts['tag_name'] == k} ti_instances.each do |ti| ti.attributes.map end end end |
#drawing_name ⇒ Object
120 121 122 |
# File 'lib/microstation/template_info.rb', line 120 def drawing_name drawing_path.basename.to_s end |
#drawing_tagsets(drawing) ⇒ Object
56 57 58 59 |
# File 'lib/microstation/template_info.rb', line 56 def (drawing) #drawing.tagsets_in_drawing_to_hash drawing. end |
#dump(dir = output_dir) ⇒ Object
128 129 130 131 |
# 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 ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 |
# 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 ⇒ Object
115 116 117 |
# 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) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# 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) @output_dir = output_dir(@drawing_path) end |
#map_tagset(mapname:, filter: tagset_name_filter, &block) ⇒ Object
88 89 90 |
# File 'lib/microstation/template_info.rb', line 88 def (mapname: , filter: , &block) @tagset_mappings[tname] = TagSetMap.new(filter, block) end |
#output_dir(l_drawing_path = @drawing_path) ⇒ Object
61 62 63 |
# 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 ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/microstation/template_info.rb', line 65 def to_h if filtered = .select{|ts| .call(ts)} else filtered = .dup end mapped_tsets = filtered.map{|ts| .call(ts)} { template: template, output_dir: output_dir, name: drawing_name, locals: locals, tagsets: mapped_tsets } end |
#to_yaml ⇒ Object
133 134 135 |
# File 'lib/microstation/template_info.rb', line 133 def to_yaml to_h.to_yaml end |
#yaml_filename ⇒ Object
124 125 126 |
# File 'lib/microstation/template_info.rb', line 124 def yaml_filename drawing_path.basename.ext('yaml') end |