Class: AskAwesomely::Field::Rating

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

Constant Summary collapse

POSSIBLE_STEPS =
1..10
VALID_SHAPES =
[
  "star",
  "heart",
  "user",
  "up",
  "crown",
  "cat",
  "dog",
  "circle",
  "flag",
  "droplet",
  "tick",
  "lightbulb",
  "trophy",
  "cloud",
  "thunderbolt",
  "pencil",
  "skull"
]

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.



25
26
27
# File 'lib/ask_awesomely/field/rating.rb', line 25

def initialize(*)
  super
end

Instance Method Details

#shape(shape) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/ask_awesomely/field/rating.rb', line 37

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

  @state.shape = shape
end

#steps(steps) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/ask_awesomely/field/rating.rb', line 29

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