Class: VisualCaptcha::Captcha
- Inherits:
-
Object
- Object
- VisualCaptcha::Captcha
- Defined in:
- lib/visualcaptcha.rb
Instance Attribute Summary collapse
-
#number ⇒ Object
Returns the value of attribute number.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(number = 4) ⇒ Captcha
constructor
A new instance of Captcha.
Constructor Details
#initialize(number = 4) ⇒ Captcha
Returns a new instance of Captcha.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/visualcaptcha.rb', line 41 def initialize(number=4) @number = number @answers = [ Option.new('airplane', 'airplane.png', 'Airplane'), Option.new('balloons', 'balloons.png', 'Balloons'), Option.new('camera', 'camera.png', 'Camera'), Option.new('car', 'car.png', 'Car'), Option.new('cat', 'cat.png', 'Cat'), Option.new('chair', 'chair.png', 'Chair'), Option.new('clip', 'clip.png', 'Clip'), Option.new('clock', 'clock.png', 'Clock'), Option.new('cloud', 'cloud.png', 'Cloud'), Option.new('computer', 'computer.png', 'Computer'), Option.new('envelope', 'envelope.png', 'Envelope'), Option.new('eye', 'eye.png', 'Eye'), Option.new('flag', 'flag.png', 'Flag'), Option.new('folder', 'folder.png', 'Folder'), Option.new('foot', 'foot.png', 'Foot'), Option.new('graph', 'graph.png', 'Graph'), Option.new('house', 'house.png', 'House'), Option.new('key', 'key.png', 'Key'), Option.new('lamp', 'lamp.png', 'Lamp'), Option.new('leaf', 'leaf.png', 'Leaf'), Option.new('lock', 'lock.png', 'Lock'), Option.new('magnifying-glass', 'magnifying-glass.png', 'Magnifying Glass'), Option.new('man', 'man.png', 'Man'), Option.new('music-note', 'music-note.png', 'Music Note'), Option.new('pants', 'pants.png', 'Pants'), Option.new('pencil', 'pencil.png', 'Pencil'), Option.new('printer', 'printer.png', 'Printer'), Option.new('robot', 'robot.png', 'Robot'), Option.new('scissors', 'scissors.png', 'Scissors'), Option.new('sunglasses', 'sunglasses.png', 'Sunglasses'), Option.new('tag', 'tag.png', 'Tag'), Option.new('tree', 'tree.png', 'Tree'), Option.new('truck', 'truck.png', 'Truck'), Option.new('tshirt', 'tshirt.png', 'T-Shirt'), Option.new('umbrella', 'umbrella.png', 'Umbrella'), Option.new('woman', 'woman.png', 'Woman'), Option.new('world', 'world.png', 'World') ] #@$this->answers = array( # 'tshirt' => array(self::$imagesPath . 'tshirt.png', 'T-Shirt'), # 'umbrella' => array(self::$imagesPath . 'umbrella.png', 'Umbrella'), # 'woman' => array(self::$imagesPath . 'woman.png', 'Woman'), # 'world' => array(self::$imagesPath . 'world.png', 'World'), #); end |
Instance Attribute Details
#number ⇒ Object
Returns the value of attribute number.
39 40 41 |
# File 'lib/visualcaptcha.rb', line 39 def number @number end |
Instance Method Details
#build ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/visualcaptcha.rb', line 91 def build #shuffle the options opts = @answers.shuffle #pick a random answer answer = opts.sample opts.reject! { |c| c.id == answer.id } others = [] #pick the remaining clues (1..@number-1).to_a.each_with_index do |c,i| possible = opts.sample others << possible opts.reject! { |c| c.id == possible.id } end #return the challenge Challenge.new(answer,others) end |