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.



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

Instance Attribute Details

#drawingObject (readonly)

Returns the value of attribute drawing.



23
24
25
# File 'lib/microstation/template_info.rb', line 23

def drawing
  @drawing
end

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

#localsObject (readonly)

Returns the value of attribute locals.



23
24
25
# File 'lib/microstation/template_info.rb', line 23

def locals
  @locals
end

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

Returns the value of attribute tagset_filter.



23
24
25
# File 'lib/microstation/template_info.rb', line 23

def tagset_filter
  @tagset_filter
end

#tagset_mapObject (readonly)

Returns the value of attribute tagset_map.



23
24
25
# File 'lib/microstation/template_info.rb', line 23

def tagset_map
  @tagset_map
end

#tagsetsObject (readonly)

Returns the value of attribute tagsets.



23
24
25
# File 'lib/microstation/template_info.rb', line 23

def tagsets
  @tagsets
end

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



80
81
82
# File 'lib/microstation/template_info.rb', line 80

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

#do_tagset_mappingsObject



92
93
94
95
96
97
98
99
100
# File 'lib/microstation/template_info.rb', line 92

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



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



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_keysObject



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_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 map_tagset(mapname: , filter: tagset_name_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_hObject



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 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_yamlObject



133
134
135
# File 'lib/microstation/template_info.rb', line 133

def to_yaml
  to_h.to_yaml
end

#yaml_filenameObject



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

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