Class: Markbridge::AST::Poll

Inherits:
Node
  • Object
show all
Defined in:
lib/markbridge/ast/poll.rb

Overview

Represents a Discourse poll.

Examples:

Basic poll

poll = AST::Poll.new(
  name: "poll",
  type: "regular",
  options: ["A", "B", "C"]
)

Poll with all attributes

poll = AST::Poll.new(
  name: "favorite-color",
  type: "multiple",
  results: "on_vote",
  public: true,
  chart_type: "pie",
  options: ["Red", "Blue", "Green"],
  raw: "[poll name=\"favorite-color\"]..."
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: "poll", type: nil, results: nil, public: false, chart_type: nil, options: [], raw: nil) ⇒ Poll

Create a new Poll node.

Parameters:

  • name (String) (defaults to: "poll")

    the poll name/identifier

  • type (String, nil) (defaults to: nil)

    poll type

  • results (String, nil) (defaults to: nil)

    when to show results

  • public (Boolean) (defaults to: false)

    whether votes are public

  • chart_type (String, nil) (defaults to: nil)

    chart type

  • options (Array<String>) (defaults to: [])

    poll options

  • raw (String, nil) (defaults to: nil)

    the original raw BBCode



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/markbridge/ast/poll.rb', line 55

def initialize(
  name: "poll",
  type: nil,
  results: nil,
  public: false,
  chart_type: nil,
  options: [],
  raw: nil
)
  @name = name
  @type = type
  @results = results
  @public = public
  @chart_type = chart_type
  @options = options
  @raw = raw
end

Instance Attribute Details

#chart_typeString? (readonly)

Returns chart type (bar, pie).

Returns:

  • (String, nil)

    chart type (bar, pie)



38
39
40
# File 'lib/markbridge/ast/poll.rb', line 38

def chart_type
  @chart_type
end

#nameString (readonly)

Returns the poll name/identifier.

Returns:

  • (String)

    the poll name/identifier



26
27
28
# File 'lib/markbridge/ast/poll.rb', line 26

def name
  @name
end

#optionsArray<String> (readonly)

Returns poll options.

Returns:

  • (Array<String>)

    poll options



41
42
43
# File 'lib/markbridge/ast/poll.rb', line 41

def options
  @options
end

#publicBoolean (readonly)

Returns whether votes are public.

Returns:

  • (Boolean)

    whether votes are public



35
36
37
# File 'lib/markbridge/ast/poll.rb', line 35

def public
  @public
end

#rawString? (readonly)

Returns the original raw BBCode.

Returns:

  • (String, nil)

    the original raw BBCode



44
45
46
# File 'lib/markbridge/ast/poll.rb', line 44

def raw
  @raw
end

#resultsString? (readonly)

Returns when to show results (always, on_vote, on_close, staff_only).

Returns:

  • (String, nil)

    when to show results (always, on_vote, on_close, staff_only)



32
33
34
# File 'lib/markbridge/ast/poll.rb', line 32

def results
  @results
end

#typeString? (readonly)

Returns poll type (regular, multiple, number).

Returns:

  • (String, nil)

    poll type (regular, multiple, number)



29
30
31
# File 'lib/markbridge/ast/poll.rb', line 29

def type
  @type
end