Class: Polites::Sheet

Inherits:
Object
  • Object
show all
Defined in:
lib/polites/sheet.rb

Overview

A sheet is represents a single "document" in Polites. It composes the main content in #content, its markup definition in #markup, any attaches files in #files and some metadata.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version:, app_version:, markup:, content:, keywords: [], files: [], notes: []) ⇒ Sheet

Returns a new instance of Sheet.

Parameters:

  • version (String)
  • app_version (String)
  • markup (Markup)
  • content (Array<Node>)
  • keywords (Array<String>) (defaults to: [])
  • files (Array<String>) (defaults to: [])
  • notes (Array<Array<Node>>) (defaults to: [])


36
37
38
39
40
41
42
43
44
# File 'lib/polites/sheet.rb', line 36

def initialize(version:, app_version:, markup:, content:, keywords: [], files: [], notes: [])
  @version = version
  @app_version = app_version
  @markup = markup
  @content = content
  @keywords = keywords
  @files = files
  @notes = notes
end

Instance Attribute Details

#app_versionString (readonly)

Returns:

  • (String)


12
13
14
# File 'lib/polites/sheet.rb', line 12

def app_version
  @app_version
end

#contentArray<Node> (readonly)

Returns:



18
19
20
# File 'lib/polites/sheet.rb', line 18

def content
  @content
end

#filesArray<String> (readonly)

Returns:

  • (Array<String>)


24
25
26
# File 'lib/polites/sheet.rb', line 24

def files
  @files
end

#keywordsArray<String> (readonly)

Returns:

  • (Array<String>)


21
22
23
# File 'lib/polites/sheet.rb', line 21

def keywords
  @keywords
end

#markupMarkup (readonly)

Returns:



15
16
17
# File 'lib/polites/sheet.rb', line 15

def markup
  @markup
end

#notesArray<Array<Node>> (readonly)

Returns:

  • (Array<Array<Node>>)


27
28
29
# File 'lib/polites/sheet.rb', line 27

def notes
  @notes
end

#versionString (readonly)

Returns:

  • (String)


9
10
11
# File 'lib/polites/sheet.rb', line 9

def version
  @version
end

Instance Method Details

#attached_filesArray<String>

Get all files that were attached to the sheet without explicit mention in the content.

Returns:

  • (Array<String>)


59
60
61
# File 'lib/polites/sheet.rb', line 59

def attached_files
  files - inline_files.map(&:image)
end

#inline_filesArray<Span::Image>

Get all files that were referenced in the content, such as inline images.

Returns:



49
50
51
52
53
# File 'lib/polites/sheet.rb', line 49

def inline_files
  content.flat_map do |node|
    node.children.grep(Span::Image)
  end
end