Class: Smartdown::Api::Flow

Inherits:
Object
  • Object
show all
Defined in:
lib/smartdown/api/flow.rb

Instance Method Summary collapse

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

#coversheetObject



71
72
73
# File 'lib/smartdown/api/flow.rb', line 71

def coversheet
  @coversheet ||= Smartdown::Api::Coversheet.new(@smartdown_flow.coversheet)
end

#draft?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/smartdown/api/flow.rb', line 44

def draft?
  status == 'draft'
end

#meta_descriptionObject



32
33
34
# File 'lib/smartdown/api/flow.rb', line 32

def meta_description
  front_matter.meta_description
end

#nameObject



24
25
26
# File 'lib/smartdown/api/flow.rb', line 24

def name
  @smartdown_flow.name
end

#need_idObject



36
37
38
# File 'lib/smartdown/api/flow.rb', line 36

def need_id
  front_matter.satisfies_need
end

#nodesObject



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

#outcomesObject



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

Returns:

  • (Boolean)


52
53
54
# File 'lib/smartdown/api/flow.rb', line 52

def published?
  status == 'published'
end

#question_pagesObject



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

#statusObject



40
41
42
# File 'lib/smartdown/api/flow.rb', line 40

def status
  front_matter.status
end

#titleObject



28
29
30
# File 'lib/smartdown/api/flow.rb', line 28

def title
  coversheet.title
end

#transition?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/smartdown/api/flow.rb', line 48

def transition?
  status == 'transition'
end