Class: ODDB::Text::Chapter

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

Constant Summary

ODBA_SERIALIZABLE =
["@sections"]
EXPORT_PROPERTIES =
[
  '@heading',
  '@sections',
]

Constants included from OddbYaml

EXPORT_PROPERTIES, YAML_URI

Constants included from Persistence

ODBA_PREDEFINE_SERIALIZABLE

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from OddbYaml

#to_yaml_properties, #to_yaml_type

Methods included from PersistenceMethods

#checkout, #data_origin, #data_origins, #diff, #init, #nil_if_empty, #parent, #pointer_descr, #structural_ancestors, #undiffable?, #update_values

Constructor Details

- (Chapter) initialize

A new instance of Chapter



214
215
216
217
# File 'src/model/text.rb', line 214

def initialize
  @heading = ''
  @sections = []
end

Instance Attribute Details

- (Object) heading

Returns the value of attribute heading



212
213
214
# File 'src/model/text.rb', line 212

def heading
  @heading
end

- (Object) sections

Returns the value of attribute sections



213
214
215
# File 'src/model/text.rb', line 213

def sections
  @sections
end

Instance Method Details

- (Object) ==(other)



267
268
269
# File 'src/model/text.rb', line 267

def ==(other)
  to_s == other.to_s
end

- (Object) clean!



218
219
220
221
222
223
224
225
# File 'src/model/text.rb', line 218

def clean!
  @heading.strip!
  @heading.gsub!(/\t+/u, ' ')
  @sections.delete_if { |section| 
    section.clean!
    section.empty? 
  }
end

- (Boolean) empty?

Returns:

  • (Boolean)


226
227
228
229
# File 'src/model/text.rb', line 226

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

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



230
231
232
233
# File 'src/model/text.rb', line 230

def gsub! *args, &block
  @sections.each do |section| section.gsub! *args, &block end
  @heading.gsub! *args, &block
end

- (Boolean) include?(section)

Returns:

  • (Boolean)


234
235
236
# File 'src/model/text.rb', line 234

def include?(section)
  @sections.include?(section)
end

- (Object) match(pattern)



245
246
247
248
249
250
# File 'src/model/text.rb', line 245

def match(pattern)
  pattern.match(@heading) or
  @sections.collect { |seq| 
    seq.match(pattern) 
  }.compact.first
end

- (Object) next_section



251
252
253
254
255
256
257
# File 'src/model/text.rb', line 251

def next_section
  if((last = @sections.last) && last.empty?)
    last
  else
    @sections.push(Section.new).last
  end
end

- (Object) paragraphs



258
259
260
261
262
263
264
265
266
# File 'src/model/text.rb', line 258

def paragraphs
  paragraphs = []
  @sections.each { |section|
    section.paragraphs.each { |par|
      paragraphs << par
    }
  }
  paragraphs
end

- (Object) to_s(opts = {})



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

def to_s opts={}

- (Object) to_search



242
243
244
# File 'src/model/text.rb', line 242

def to_search
  ODDB.search_term(to_s)
end