Class: Smartdown::Api::Flow
- Inherits:
-
Object
- Object
- Smartdown::Api::Flow
- Defined in:
- lib/smartdown/api/flow.rb
Instance Method Summary collapse
- #coversheet ⇒ Object
- #draft? ⇒ Boolean
-
#initialize(smartdown_input, initial_state = {}) ⇒ Flow
constructor
A new instance of Flow.
- #meta_description ⇒ Object
- #name ⇒ Object
- #need_id ⇒ Object
- #nodes ⇒ Object
- #outcomes ⇒ Object
- #published? ⇒ Boolean
- #question_pages ⇒ Object
- #state(started, responses) ⇒ Object
- #status ⇒ Object
- #title ⇒ Object
- #transition? ⇒ Boolean
Constructor Details
#initialize(smartdown_input, initial_state = {}) ⇒ Flow
Returns a new instance of Flow.
11 12 13 14 |
# File 'lib/smartdown/api/flow.rb', line 11 def initialize(smartdown_input, initial_state = {}) @smartdown_flow = Smartdown::Parser::FlowInterpreter.new(smartdown_input).interpret @engine = Smartdown::Engine.new(@smartdown_flow, initial_state) end |
Instance Method Details
#coversheet ⇒ Object
71 72 73 |
# File 'lib/smartdown/api/flow.rb', line 71 def coversheet @coversheet ||= Smartdown::Api::Coversheet.new(@smartdown_flow.coversheet) end |
#draft? ⇒ Boolean
44 45 46 |
# File 'lib/smartdown/api/flow.rb', line 44 def draft? status == 'draft' end |
#meta_description ⇒ Object
32 33 34 |
# File 'lib/smartdown/api/flow.rb', line 32 def front_matter. end |
#name ⇒ Object
24 25 26 |
# File 'lib/smartdown/api/flow.rb', line 24 def name @smartdown_flow.name end |
#need_id ⇒ Object
36 37 38 |
# File 'lib/smartdown/api/flow.rb', line 36 def need_id front_matter.satisfies_need end |
#nodes ⇒ Object
56 57 58 59 60 61 |
# File 'lib/smartdown/api/flow.rb', line 56 def nodes @smartdown_flow.nodes.map{ |node| transform_node(node) } .select{ |node| (node.is_a? Smartdown::Api::QuestionPage) || (node.is_a? Smartdown::Api::Outcome) } end |
#outcomes ⇒ Object
67 68 69 |
# File 'lib/smartdown/api/flow.rb', line 67 def outcomes nodes.select{ |node| node.is_a? Smartdown::Api::Outcome} end |
#published? ⇒ Boolean
52 53 54 |
# File 'lib/smartdown/api/flow.rb', line 52 def published? status == 'published' end |
#question_pages ⇒ Object
63 64 65 |
# File 'lib/smartdown/api/flow.rb', line 63 def question_pages nodes.select{ |node| node.is_a? Smartdown::Api::QuestionPage } end |
#state(started, responses) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/smartdown/api/flow.rb', line 16 def state(started, responses) state = smartdown_state(started, responses) State.new(transform_node(evaluate_node(node_by_name(state.get(:current_node)), state)), previous_question_nodes_for(state), responses ) end |
#status ⇒ Object
40 41 42 |
# File 'lib/smartdown/api/flow.rb', line 40 def status front_matter.status end |
#title ⇒ Object
28 29 30 |
# File 'lib/smartdown/api/flow.rb', line 28 def title coversheet.title end |
#transition? ⇒ Boolean
48 49 50 |
# File 'lib/smartdown/api/flow.rb', line 48 def transition? status == 'transition' end |