Class: Microstation::TextNode

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

Instance Attribute Summary collapse

Attributes inherited from Element

#app

Instance Method Summary collapse

Methods inherited from Element

#[], #app_ole_obj, convert_item, #do_update, #each, #each_cell, #each_complex, #get_property_handler, #in_cell?, #initialize, #ole_cell, ole_object?, #property_handler, #redraw, #update, #updated?

Methods included from ElementTrait

#cell?, #complex?, #graphical?, #has_tags?, #id_from_record, #line?, #microstation_id, #microstation_type, #model, #parent, #select, #text_node?, #textual?, #to_ole

Constructor Details

This class inherits a constructor from Microstation::Element

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



93
94
95
96
97
98
99
100
101
102
# File 'lib/microstation/text_node.rb', line 93

def method_missing(meth, *args, &block)
  if /^[A-Z]/.match?(meth)
    ole_obj.send(meth, *args)
  else
    copy = @original.dup
    result = copy.send(meth, *args, &block)
    update(result) unless copy == @original
    result
  end
end

Instance Attribute Details

#ole_objObject (readonly)

Returns the value of attribute ole_obj.



3
4
5
# File 'lib/microstation/text_node.rb', line 3

def ole_obj
  @ole_obj
end

#originalObject (readonly)

Returns the value of attribute original.



3
4
5
# File 'lib/microstation/text_node.rb', line 3

def original
  @original
end

Instance Method Details

#=~(reg) ⇒ Object



76
77
78
# File 'lib/microstation/text_node.rb', line 76

def =~(reg)
  @original =~ reg
end

#empty?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/microstation/text_node.rb', line 9

def empty?
  ole_obj.TextLinesCount == 0
end

#read_ole(ole) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/microstation/text_node.rb', line 21

def read_ole(ole)
  count = ole.TextLinesCount
  #    debugger if count > 0

  str_array = []
  1.upto(count) do |i|
    str_array << ole.TextLine(i)
  end
  str_array.join("\n")
end

#render(h = {}) ⇒ Object



84
85
86
87
88
89
90
91
# File 'lib/microstation/text_node.rb', line 84

def render(h = {})
  return self unless template?

  template = Liquid::Template.parse(to_s)
  result = template.render(h)
  update(result) unless result == @original
  self
end

#sizeObject



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

def size
  ole_obj.TextLinesCount
end

#template?Boolean

Returns:

  • (Boolean)


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

def template?
  !!(@original =~ /{{.+}}/)
end

#text?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/microstation/text_node.rb', line 13

def text?
  false
end

#to_regexpObject



5
6
7
# File 'lib/microstation/text_node.rb', line 5

def to_regexp
  Regexp.new(original.to_s)
end

#to_sObject



72
73
74
# File 'lib/microstation/text_node.rb', line 72

def to_s
  @original.to_s
end

#update_ole!(text) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/microstation/text_node.rb', line 63

def update_ole!(text)
  ole_obj.DeleteAllTextLines
  text.each_line do |line|
    ole_obj.AddTextLine(line)
  end
  ole_obj.Redraw Microstation::MSD::MsdDrawingModeNormal
  ole_obj.Rewrite
end

#write_ole(text) ⇒ Object

def _update(text)

update_ole!(text)
@original = text

end



36
37
38
39
40
41
42
# File 'lib/microstation/text_node.rb', line 36

def write_ole(text)
  if in_cell?
    write_ole_in_cell(text)
  else
    write_ole_regular(text)
  end
end

#write_ole_in_cell(text) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/microstation/text_node.rb', line 51

def write_ole_in_cell(text)
  orig_ole = ole_obj
  new_text_ole = ole_obj.Clone
  new_text_ole.DeleteAllTextLines
  text.each_line do |line|
    new_text_ole.AddTextLine(line)
  end
  @ole_obj = new_text_ole
rescue => e
  @ole_obj = orig_ole
end

#write_ole_regular(text) ⇒ Object



44
45
46
47
48
49
# File 'lib/microstation/text_node.rb', line 44

def write_ole_regular(text)
  ole_obj.DeleteAllTextLines
  text.each_line do |line|
    ole_obj.AddTextLine(line)
  end
end