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.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/microstation/template_info.rb', line 19 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 = = self end |
Instance Attribute Details
#drawing ⇒ Object (readonly)
Returns the value of attribute drawing.
17 18 19 |
# File 'lib/microstation/template_info.rb', line 17 def drawing @drawing end |
#drawing_path ⇒ Object (readonly)
Returns the value of attribute drawing_path.
17 18 19 |
# File 'lib/microstation/template_info.rb', line 17 def drawing_path @drawing_path end |
#locals ⇒ Object (readonly)
Returns the value of attribute locals.
17 18 19 |
# File 'lib/microstation/template_info.rb', line 17 def locals @locals end |
#placeholder_keys ⇒ Object (readonly)
Returns the value of attribute placeholder_keys.
17 18 19 |
# File 'lib/microstation/template_info.rb', line 17 def placeholder_keys @placeholder_keys end |
#tagset_filter ⇒ Object (readonly)
Returns the value of attribute tagset_filter.
17 18 19 |
# File 'lib/microstation/template_info.rb', line 17 def end |
#tagset_map ⇒ Object (readonly)
Returns the value of attribute tagset_map.
17 18 19 |
# File 'lib/microstation/template_info.rb', line 17 def end |
#tagsets ⇒ Object (readonly)
Returns the value of attribute tagsets.
17 18 19 |
# File 'lib/microstation/template_info.rb', line 17 def end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
17 18 19 |
# File 'lib/microstation/template_info.rb', line 17 def template @template end |
Instance Method Details
#before_locals(locals) ⇒ Object
77 78 79 |
# File 'lib/microstation/template_info.rb', line 77 def before_locals(locals) locals end |
#default_filter ⇒ Object
73 74 75 |
# File 'lib/microstation/template_info.rb', line 73 def default_filter ->(ts) { ts.name == "faatitle" } end |
#do_tagset_mappings ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/microstation/template_info.rb', line 85 def .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
112 113 114 |
# File 'lib/microstation/template_info.rb', line 112 def drawing_name drawing_path.basename.to_s end |
#drawing_tagsets(drawing) ⇒ Object
50 51 52 53 |
# File 'lib/microstation/template_info.rb', line 50 def (drawing) # drawing.tagsets_in_drawing_to_hash drawing. end |
#dump(dir = output_dir) ⇒ Object
120 121 122 123 |
# File 'lib/microstation/template_info.rb', line 120 def dump(dir = output_dir) dir = Pathname(dir) File.open(dir + yaml_filename, "w") { |f| f.puts to_yaml } end |
#faa_map ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/microstation/template_info.rb', line 95 def faa_map lambda { |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
108 109 110 |
# File 'lib/microstation/template_info.rb', line 108 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
40 41 42 43 44 45 46 47 48 |
# File 'lib/microstation/template_info.rb', line 40 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 = (drawing) @output_dir = output_dir(@drawing_path) end |
#map_tagset(mapname:, filter: tagset_name_filter, &block) ⇒ Object
81 82 83 |
# File 'lib/microstation/template_info.rb', line 81 def (mapname:, filter: , &block) [tname] = TagSetMap.new(filter, block) end |
#output_dir(l_drawing_path = @drawing_path) ⇒ Object
55 56 57 |
# File 'lib/microstation/template_info.rb', line 55 def output_dir(l_drawing_path = @drawing_path) l_drawing_path.parent.to_s end |
#to_h ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/microstation/template_info.rb', line 59 def to_h filtered = if .select { |ts| .call(ts) } else .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
125 126 127 |
# File 'lib/microstation/template_info.rb', line 125 def to_yaml to_h.to_yaml end |
#yaml_filename ⇒ Object
116 117 118 |
# File 'lib/microstation/template_info.rb', line 116 def yaml_filename drawing_path.basename.ext("yaml") end |