Class: Microstation::TemplateInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/microstation/template_info.rb

Defined Under Namespace

Classes: TagSetMap

Constant Summary collapse

LIQUID_REGEXP =
/{{([^}]+)}}/

Instance Attribute Summary collapse

Instance Method Summary collapse

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
  @tagset_filter = tagset_filter
  @tagset_map = tagset_map
  self
end

Instance Attribute Details

#drawingObject (readonly)

Returns the value of attribute drawing.



17
18
19
# File 'lib/microstation/template_info.rb', line 17

def drawing
  @drawing
end

#drawing_pathObject (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

#localsObject (readonly)

Returns the value of attribute locals.



17
18
19
# File 'lib/microstation/template_info.rb', line 17

def locals
  @locals
end

#placeholder_keysObject (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_filterObject (readonly)

Returns the value of attribute tagset_filter.



17
18
19
# File 'lib/microstation/template_info.rb', line 17

def tagset_filter
  @tagset_filter
end

#tagset_mapObject (readonly)

Returns the value of attribute tagset_map.



17
18
19
# File 'lib/microstation/template_info.rb', line 17

def tagset_map
  @tagset_map
end

#tagsetsObject (readonly)

Returns the value of attribute tagsets.



17
18
19
# File 'lib/microstation/template_info.rb', line 17

def tagsets
  @tagsets
end

#templateObject (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_filterObject



73
74
75
# File 'lib/microstation/template_info.rb', line 73

def default_filter
  ->(ts) { ts.name == "faatitle" }
end

#do_tagset_mappingsObject



85
86
87
88
89
90
91
92
93
# File 'lib/microstation/template_info.rb', line 85

def do_tagset_mappings
  @tagset_mappings.each do |ts_mapper|
    ts_mapper.call(tagsets)
    ti_instances = tagsets.select { |ts| ts["tag_name"] == k }
    ti_instances.each do |ti|
      ti.attributes.map
    end
  end
end

#drawing_nameObject



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_tagsets(drawing)
  # drawing.tagsets_in_drawing_to_hash

  drawing.tagsets_in_drawing_to_hash
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_mapObject



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_keysObject



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
  @tagsets = drawing_tagsets(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 map_tagset(mapname:, filter: tagset_name_filter, &block)
  @tagset_mappings[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_hObject



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 tagset_filter
    tagsets.select { |ts| tagset_filter.call(ts) }
  else
    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_yamlObject



125
126
127
# File 'lib/microstation/template_info.rb', line 125

def to_yaml
  to_h.to_yaml
end

#yaml_filenameObject



116
117
118
# File 'lib/microstation/template_info.rb', line 116

def yaml_filename
  drawing_path.basename.ext("yaml")
end