Class: AskAwesomely::Field::Rating

Inherits:
Field
  • Object
show all
Defined in:
lib/ask_awesomely/field/rating.rb

Constant Summary collapse

POSSIBLE_STEPS =
3..10
SHAPES =
%i(
  stars
  thumbs_up
)

Constants inherited from Field

Field::VALID_FIELD_TYPES

Instance Attribute Summary

Attributes inherited from Field

#state

Instance Method Summary collapse

Methods inherited from Field

#ask, #description, of_type, #ref, #required, #skip, #tags

Methods included from JsonBuilder

#build_json

Constructor Details

#initializeRating

Returns a new instance of Rating.



10
11
12
# File 'lib/ask_awesomely/field/rating.rb', line 10

def initialize(*)
  super
end

Instance Method Details

#shape(shape) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/ask_awesomely/field/rating.rb', line 22

def shape(shape)
  unless SHAPES.include?(shape)
    raise ArgumentError, "shape must be one of: #{SHAPES.join(", ")}"
  end

  @state.shape = shape
end

#steps(steps) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/ask_awesomely/field/rating.rb', line 14

def steps(steps)
  unless POSSIBLE_STEPS.cover?(steps)
    raise ArgumentError, "number of steps must be between #{POSSIBLE_STEPS.begin} and #{POSSIBLE_STEPS.end}"
  end

  @state.steps = steps
end