Class: Konjac::Office::Base::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/konjac/office/item.rb

Overview

An item class dealing with hierarchy in which to search the document. For example, with Word it will search paragraphs and for PowerPoint it will search slides then shapes. This class then will follow the hierarchy to text objects and is capable of reading from and writing to them.

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Item

Creates a new Item



12
13
14
15
16
17
18
19
20
# File 'lib/konjac/office/item.rb', line 12

def initialize(opts = {})
  @opts = opts

  item = @opts[:document]
  @opts[:ref_path].each do |node|
    item = item.send(pluralize(node))[opts[node]]
  end
  @ref = item
end

Instance Method Details

#contentObject

Retrieves the content from the Item. Note that without getter or setter methods this may not actually retrieve anything but the message we intend to send to the scripting interface.



25
26
27
28
29
30
31
32
33
# File 'lib/konjac/office/item.rb', line 25

def content
  return @content unless @content.nil?

  @content = @ref
  @opts[:content_path].each do |node|
    @content = @content.send(node)
  end
  @content
end

#readObject

Reads the item’s text content, cleaned up according to the supplied delimiters and strippable items



37
38
39
# File 'lib/konjac/office/item.rb', line 37

def read
  clean content.send(@opts[:read])
end

#write(text) ⇒ Object

Writes to the item



42
43
44
# File 'lib/konjac/office/item.rb', line 42

def write(text)
  content.send @opts[:write], text
end