Class: MarkdownComposer::Plan
- Inherits:
-
Object
- Object
- MarkdownComposer::Plan
- Defined in:
- lib/markdown_composer/plan.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#diagnostics ⇒ Object
readonly
Returns the value of attribute diagnostics.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(config) ⇒ Plan
constructor
A new instance of Plan.
- #output ⇒ Object
- #steps ⇒ Object
- #to_h ⇒ Object
- #transforms ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(config) ⇒ Plan
Returns a new instance of Plan.
21 22 23 24 |
# File 'lib/markdown_composer/plan.rb', line 21 def initialize(config) @diagnostics = Diagnostics.new @config = normalize(config || {}) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/markdown_composer/plan.rb', line 5 def config @config end |
#diagnostics ⇒ Object (readonly)
Returns the value of attribute diagnostics.
5 6 7 |
# File 'lib/markdown_composer/plan.rb', line 5 def diagnostics @diagnostics end |
Class Method Details
.from_rows(row_hashes) ⇒ Object
13 14 15 |
# File 'lib/markdown_composer/plan.rb', line 13 def self.from_rows(row_hashes) new("compose" => Array(row_hashes).map { |row| normalize_hash(row) }) end |
.invalid(code, message) ⇒ Object
7 8 9 10 11 |
# File 'lib/markdown_composer/plan.rb', line 7 def self.invalid(code, ) plan = new({}) plan.diagnostics.error(code, ) plan end |
.normalize_hash(value) ⇒ Object
17 18 19 |
# File 'lib/markdown_composer/plan.rb', line 17 def self.normalize_hash(value) value.to_h.transform_keys { |key| key.to_s.downcase.tr(" ", "_") } end |
Instance Method Details
#output ⇒ Object
30 31 32 |
# File 'lib/markdown_composer/plan.rb', line 30 def output config.fetch("output", "markdown").to_s end |
#steps ⇒ Object
34 35 36 |
# File 'lib/markdown_composer/plan.rb', line 34 def steps Array(compose_config).map { |step| normalize_step(step) } end |
#to_h ⇒ Object
42 43 44 45 |
# File 'lib/markdown_composer/plan.rb', line 42 def to_h canonical = config.reject { |key, _value| %w[steps transforms compose transform].include?(key) } canonical.merge("compose" => steps, "transform" => transforms, "output" => output) end |
#transforms ⇒ Object
38 39 40 |
# File 'lib/markdown_composer/plan.rb', line 38 def transforms Array(transform_config).map.with_index { |transform, index| normalize_transform(transform, path: "transform[#{index}]") } end |
#version ⇒ Object
26 27 28 |
# File 'lib/markdown_composer/plan.rb', line 26 def version config.fetch("version", 1) end |