Class: Fig::PackageDefinitionTextAssembler

Inherits:
Object
  • Object
show all
Defined in:
lib/fig/package_definition_text_assembler.rb

Overview

Used for building packages for publishing.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(emit_as_input_or_to_be_published_values) ⇒ PackageDefinitionTextAssembler

Returns a new instance of PackageDefinitionTextAssembler.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fig/package_definition_text_assembler.rb', line 16

def initialize(emit_as_input_or_to_be_published_values)
  @emit_as_input_or_to_be_published_values =
    emit_as_input_or_to_be_published_values

  @input_statements   = []
  @output_statements  = []
  @header_text        = []
  @footer_text        = []

  return
end

Instance Attribute Details

#input_statementsObject (readonly)

Returns the value of attribute input_statements.



13
14
15
# File 'lib/fig/package_definition_text_assembler.rb', line 13

def input_statements
  @input_statements
end

#output_statementsObject (readonly)

Returns the value of attribute output_statements.



14
15
16
# File 'lib/fig/package_definition_text_assembler.rb', line 14

def output_statements
  @output_statements
end

Instance Method Details

Argument can be a single string or an array of strings



59
60
61
62
63
# File 'lib/fig/package_definition_text_assembler.rb', line 59

def add_footer(text)
  @footer_text << text

  return
end

#add_header(text) ⇒ Object

Argument can be a single string or an array of strings



52
53
54
55
56
# File 'lib/fig/package_definition_text_assembler.rb', line 52

def add_header(text)
  @header_text << text

  return
end

#add_input(statements) ⇒ Object

Argument can either be a single Statement or an array of them.



29
30
31
32
33
34
# File 'lib/fig/package_definition_text_assembler.rb', line 29

def add_input(statements)
  @input_statements << statements
  @input_statements.flatten!

  return
end

#add_output(*statements) ⇒ Object

Argument can either be a single Statement or an array of them.



37
38
39
40
41
42
43
44
45
# File 'lib/fig/package_definition_text_assembler.rb', line 37

def add_output(*statements)
  # Version gets determined by other statements, not by existing grammar.
  @output_statements <<
    statements.flatten.reject { |s| s.is_a? Fig::Statement::GrammarVersion }

  @output_statements.flatten!

  return
end

#assemble_package_definitionObject



65
66
67
68
69
70
71
72
73
74
# File 'lib/fig/package_definition_text_assembler.rb', line 65

def assemble_package_definition()
  unparsed_statements, explanations = deparse_statements()
  definition =
    [@header_text, unparsed_statements, @footer_text].flatten.join("\n")
  definition.gsub!(/\n{3,}/, "\n\n")
  definition.strip!
  definition << "\n"

  return definition, explanations
end

#asset_input_statementsObject



47
48
49
# File 'lib/fig/package_definition_text_assembler.rb', line 47

def asset_input_statements()
  return @input_statements.select { |statement| statement.is_asset? }
end