Class: ODDB::Text::Section

Inherits:
Object show all
Includes:
OddbYaml
Defined in:
src/model/text.rb,
ext/export/src/oddb_yaml.rb

Constant Summary

EXPORT_PROPERTIES =
[
  '@subheading',
  '@paragraphs',
]

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

- (Section) initialize

A new instance of Section



168
169
170
171
# File 'src/model/text.rb', line 168

def initialize
  @subheading = ''
  @paragraphs = []
end

Instance Attribute Details

- (Object) paragraphs (readonly)

Returns the value of attribute paragraphs



167
168
169
# File 'src/model/text.rb', line 167

def paragraphs
  @paragraphs
end

- (Object) subheading

Returns the value of attribute subheading



166
167
168
# File 'src/model/text.rb', line 166

def subheading
  @subheading
end

Instance Method Details

- (Object) clean!



172
173
174
175
176
177
178
# File 'src/model/text.rb', line 172

def clean!
  @paragraphs.compact!
  @subheading.gsub!(/(^\s*)|([ \t\r]*$)/u, '')
  @subheading.gsub!(/\t+/u, ' ')
  @paragraphs.delete_if { |paragraph| paragraph.empty? }
  @paragraphs.each do |paragraph| paragraph.clean! end
end

- (Boolean) empty?

Returns:

  • (Boolean)


179
180
181
182
# File 'src/model/text.rb', line 179

def empty?
  #clean! ## empty? should have no side-effects!
  @subheading.empty? && @paragraphs.empty?
end

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



183
184
185
186
# File 'src/model/text.rb', line 183

def gsub! *args, &block
  @paragraphs.each do |paragraph| paragraph.gsub! *args, &block end
  @subheading.gsub! *args, &block
end

- (Object) match(pattern)



192
193
194
195
196
197
# File 'src/model/text.rb', line 192

def match(pattern)
  pattern.match(@subheading) or
  @paragraphs.collect { |par| 
    par.match(pattern) 
  }.compact.first
end

- (Object) next_image



198
199
200
# File 'src/model/text.rb', line 198

def next_image
  @paragraphs.push(ImageLink.new).last
end

- (Object) next_paragraph



201
202
203
204
205
206
207
# File 'src/model/text.rb', line 201

def next_paragraph
  if((last = @paragraphs.last) && last.empty?)
    last
  else
    @paragraphs.push(Paragraph.new).last
  end
end

- (Object) to_s(opts = {})



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

def to_s opts={}