Class: Idml::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/idml/document.rb

Overview

Cross-part read-only view over a Package. The Package layer stops at "give me part X"; the Document layer answers questions that span parts. Every query routes through typed model methods on the parts — no ad-hoc XML libraries.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(package) ⇒ Document

Returns a new instance of Document.



9
10
11
# File 'lib/idml/document.rb', line 9

def initialize(package)
  @package = package
end

Instance Attribute Details

#packageObject (readonly)

Returns the value of attribute package.



13
14
15
# File 'lib/idml/document.rb', line 13

def package
  @package
end

Instance Method Details

#dom_versionObject



15
16
17
# File 'lib/idml/document.rb', line 15

def dom_version
  @package.dom_version
end

#each_storyObject



38
39
40
41
42
43
44
# File 'lib/idml/document.rb', line 38

def each_story
  return enum_for(:each_story) unless block_given?

  @package.stories.each do |story|
    yield story.self_id, story.text_content
  end
end

#find_by_self(self_id) ⇒ Object

Locate the part that contains the given Self id. Returns the part name (e.g., "Stories/Story_u164.xml") or nil. String-based search — works for any Self on any element, regardless of typed coverage.



23
24
25
26
27
28
29
30
31
# File 'lib/idml/document.rb', line 23

def find_by_self(self_id)
  pattern = %(Self="#{self_id}")
  @package.part_names.each do |name|
    next if non_searchable?(name)

    return name if @package.read_part(name).include?(pattern)
  end
  nil
end

#story_text(story_self) ⇒ Object



33
34
35
36
# File 'lib/idml/document.rb', line 33

def story_text(story_self)
  story = stories_by_self[story_self]
  story ? story.text_content : ""
end

#tagged_elementsObject



50
51
52
# File 'lib/idml/document.rb', line 50

def tagged_elements
  tagged_in_stories + tagged_in_backing_story
end

#xml_structureObject



46
47
48
# File 'lib/idml/document.rb', line 46

def xml_structure
  @package.backing_story
end