Class: ODDB::Text::Paragraph

Inherits:
Object
  • Object
show all
Includes:
OddbYaml
Defined in:
src/model/text.rb,
test/test_model/text.rb,
ext/export/src/oddb_yaml.rb,
ext/fipdf/test/fachinfo_writer_test.rb

Direct Known Subclasses

Cell

Constant Summary

EXPORT_PROPERTIES =
[
  '@formats',
  '@text',
  '@preformatted',
]

Constants included from OddbYaml

EXPORT_PROPERTIES, YAML_URI

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from OddbYaml

#to_yaml_properties, #to_yaml_type

Constructor Details

- (Paragraph) initialize

A new instance of Paragraph



60
61
62
# File 'src/model/text.rb', line 60

def initialize
  clear!
end

Instance Attribute Details

- (Object) formats (readonly)

Returns the value of attribute formats



59
60
61
# File 'src/model/text.rb', line 59

def formats
  @formats
end

- (Object) text

Returns the value of attribute text



59
60
61
# File 'src/model/text.rb', line 59

def text
  @text
end

Instance Method Details

- (Object) <<(text)



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'src/model/text.rb', line 135

def <<(text)
  @raw_txt ||= @text.dup
  if(!@preformatted \
     && /[‐­-]\s*$/u.match(@raw_txt) && /^[[:lower:]]/u.match(text))
    # if we're appending to a hyphen, and text starts with a lowercase
    # letter, we need to remove the hyphen
    @raw_txt.gsub! /[‐­-]\s*$/u, ''
  end
  @raw_txt << text.to_s
  @raw_txt.gsub!(/[\n\r]+/u, "\n")
  @raw_txt.gsub!(/^\n+/u, "")
  if(@preformatted)
    @raw_txt.gsub!(/(.*?)\t/u) { |match|
      str = match[0..-2]
      str << (" " * (8 - (str.length % 8)))
    }
  else
    @raw_txt.gsub! /\t+/u, ' '
  end
  if(@preformatted)
    @text = @raw_txt.dup
  else
    @text = @raw_txt.strip
  end
  self
end

- (Object) [](*args)



161
162
163
# File 'src/model/text.rb', line 161

def [](*args)
  (@raw_txt || @text)[*args]
end

- (Object) augment_format(*args)



63
64
65
# File 'src/model/text.rb', line 63

def augment_format(*args)
  set_format(*(@format.values + args))
end

- (Object) clean!



66
67
68
69
# File 'src/model/text.rb', line 66

def clean!
  @text.gsub! /\t/u, ' '
  @raw_txt = nil
end

- (Object) clear!



70
71
72
73
74
75
76
# File 'src/model/text.rb', line 70

def clear!
  @formats = []
  @raw_txt = ''
  @text = ''
  @preformatted = false
  set_format()
end

- (Boolean) empty?

Returns:

  • (Boolean)


77
78
79
# File 'src/model/text.rb', line 77

def empty?
  @text.empty?
end

- (Object) gsub!(*args, &block)



80
81
82
83
# File 'src/model/text.rb', line 80

def gsub! *args, &block
  @raw_txt.gsub! *args, &block if @raw_txt
  @text.gsub! *args, &block
end

- (Object) length



84
85
86
# File 'src/model/text.rb', line 84

def length
  @text.length
end

- (Object) match(pattern)



87
88
89
# File 'src/model/text.rb', line 87

def match(pattern)
  @text.match(pattern)
end

- (Object) preformatted!



90
91
92
# File 'src/model/text.rb', line 90

def preformatted!
  @preformatted = true
end

- (Boolean) preformatted?

Returns:

  • (Boolean)


93
94
95
# File 'src/model/text.rb', line 93

def preformatted?
  @preformatted
end

- (Object) prepend(text, *format_args)



96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'src/model/text.rb', line 96

def prepend(text, *format_args)
  text_length = text.length
  @formats.each { |format|
    format.start += text_length
    unless(format.end < 0)
      format.end += text_length
    end
  }
  format = Text::Format.new(*format_args)
  format.end = (text_length - 1)
  @formats.unshift(format)
  @raw_txt = text + (@raw_txt || @text)
  @text = @raw_txt.strip
end

- (Object) reduce_format(*args)



110
111
112
# File 'src/model/text.rb', line 110

def reduce_format(*args)
  set_format(*(@format.values - args))
end

- (Object) set_format(*args)



113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'src/model/text.rb', line 113

def set_format(*args)
  len = u(@text).length
  unless(@format.nil?)
    if(@format.start == len)
      @formats.pop
    else
      @format.end = (len - 1)
    end
  end
  @format = Text::Format.new(*args)
  @format.start = (len)
  @formats.push(@format)
  @format
end

- (Object) strip



127
128
129
# File 'src/model/text.rb', line 127

def strip
  @text.strip
end

- (Object) to_s(opts = {})



130
# File 'src/model/text.rb', line 130

def to_s opts={}