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



99
100
101
102
103
104
105
106
107
108
# File 'lib/microstation/text_node.rb', line 99

def method_missing(meth,*args,&block)
  if meth =~ /^[A-Z]/
    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.



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

def ole_obj
  @ole_obj
end

#originalObject (readonly)

Returns the value of attribute original.



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

def original
  @original
end

Instance Method Details

#=~(reg) ⇒ Object



83
84
85
# File 'lib/microstation/text_node.rb', line 83

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

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  ole_obj.TextLinesCount == 0
end

#read_ole(ole) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/microstation/text_node.rb', line 26

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



91
92
93
94
95
96
97
# File 'lib/microstation/text_node.rb', line 91

def render(h={})
  return self unless  template?
  template = Liquid::Template.parse(self.to_s)
  result = template.render(h)
  update(result) unless result == @original
  self
end

#sizeObject



21
22
23
# File 'lib/microstation/text_node.rb', line 21

def size
  ole_obj.TextLinesCount
end

#template?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/microstation/text_node.rb', line 87

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

#text?Boolean

Returns:

  • (Boolean)


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

def text?
  false
end

#to_regexpObject



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

def to_regexp
  Regexp.new(original.to_s)
end

#to_sObject



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

def to_s
  @original.to_s
end

#update_ole!(text) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/microstation/text_node.rb', line 70

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



41
42
43
44
45
46
47
# File 'lib/microstation/text_node.rb', line 41

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



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/microstation/text_node.rb', line 56

def write_ole_in_cell(text)
  begin
    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
end

#write_ole_regular(text) ⇒ Object



49
50
51
52
53
54
# File 'lib/microstation/text_node.rb', line 49

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