stroop 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6aab77ba17a5345e1eb6a60f6a5a5db7306df7eb
4
+ data.tar.gz: ee2a0f808ec2fc3febb13259bbaf0aded5630fd9
5
+ SHA512:
6
+ metadata.gz: 88ef238dc777b031cd082a570484c2be65b1b47f35dcf689bf0093fe2e6895f4404adbbe327541eb2e45fb0d09707bbf4cfa21ef0a343ee1b415139dfda65e9b
7
+ data.tar.gz: da92237c03e285e2c516aff46fb94a54c5019f123924ac16389b2bc567ebdcf57f04f2fc49f3af72dcb0c70c1da4317efeb9c30c2ad7a0a4a0a0e58442b89e62
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ pkg/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ sudo: false
2
+ language: ruby
3
+
4
+ rvm:
5
+ - 2.2
6
+ - 2.1
7
+ - rbx-2
8
+ - jruby-head
9
+ - jruby-9000
10
+
11
+ cache:
12
+ - bundler
13
+
14
+ matrix:
15
+ fast_finish: true
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ ## CHANGELOG
2
+
3
+ ### 0.1.0
4
+
5
+ * Inital release
6
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ stroop (0.1.0)
5
+ colorize (~> 0.7)
6
+ thor (~> 0.19)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ colorize (0.7.7)
12
+ diff-lcs (1.2.5)
13
+ rake (10.4.2)
14
+ rspec (3.3.0)
15
+ rspec-core (~> 3.3.0)
16
+ rspec-expectations (~> 3.3.0)
17
+ rspec-mocks (~> 3.3.0)
18
+ rspec-core (3.3.2)
19
+ rspec-support (~> 3.3.0)
20
+ rspec-expectations (3.3.1)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.3.0)
23
+ rspec-mocks (3.3.2)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.3.0)
26
+ rspec-support (3.3.0)
27
+ thor (0.19.1)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ rake (~> 10.0)
34
+ rspec (~> 3.0)
35
+ stroop!
data/MIT-LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2015 Paul Götze, paul.christoph.goetze@gmail.com
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # Stroop [![[version]](https://badge.fury.io/rb/stroop.svg)](http://badge.fury.io/rb/stroop) [![[travis]](https://travis-ci.org/paulgoetze/stroop.png)](https://travis-ci.org/paulgoetze/stroop)
2
+
3
+ Stroop is a tiny CLI for printing Stroop tests in order to experience the psychological [Stroop effect](https://en.wikipedia.org/wiki/Stroop_effect).
4
+
5
+ The Stroop effect demonstrates the interference in the reaction time of a task.
6
+ The CLI prints a number of color words in 3 different stimuli:
7
+
8
+ 1. Neutral: each words is written in the same color (black)
9
+ 2. Congruent: the text color and the word refer to the same color
10
+ 3. Incongruent: the text color and the word do not refer to the same color
11
+
12
+ ## Setup
13
+
14
+ Install the gem with:
15
+
16
+ ```ruby
17
+ gem install stroop
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ In the terminal type:
23
+
24
+ ```bash
25
+ # printing a neutral stimuli
26
+ # (text displayed in one color):
27
+ $ stroop neutral 5x10
28
+
29
+ # printing congruent stimuli
30
+ # (text color and word refer to the same color):
31
+ $ stroop congruent 5x10
32
+
33
+ # printing incongruent stimuli
34
+ # (text color and word do not refer to the same color):
35
+ $ stroop incongruent 5x10
36
+ ```
37
+
38
+ This will print you a Stroop test of 10 lines of words with 5 words in each of them.
39
+
40
+ You can adjust the rows and columns of words by changing the `CxR` param as you like (e.g. `5x2`). If you leave it out a default of `5x10` is used.
41
+
42
+ If you want to use Stroop in Ruby you can run the following code:
43
+
44
+ ```ruby
45
+ require 'stroop'
46
+
47
+ # adjust rows and columns to whatever you like
48
+ set = Stroop::Set.new(columns: 5, rows: 10, mode: Stroop::Set::NEUTRAL)
49
+ set.to_s # => returns the string of colorized words
50
+ ```
51
+
52
+ The available Stroop::Set modes are:
53
+
54
+ ```ruby
55
+ Stroop::Set::NEUTRAL # => :neutral
56
+ Stroop::Set::CONGRUENT # => :congruent
57
+ Stroop::Set::INCONGRUENT # => :incongruent
58
+ ```
59
+
60
+ ## MIT License
61
+
62
+ Copyright (C) 2015 Paul Götze. Released under the MIT license.
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ require "rspec/core/rake_task"
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
4
+ task :default => :spec
5
+
6
+ # Get gemspec info
7
+ gemspec_file = Dir['*.gemspec'].first
8
+ gemspec = eval File.read(gemspec_file), binding, gemspec_file
9
+ info = "#{gemspec.name} | #{gemspec.version} | " \
10
+ "#{gemspec.runtime_dependencies.size} dependencies | " \
11
+ "#{gemspec.files.size} files"
12
+
13
+ # Gem build and install task
14
+ desc info
15
+ task :gem do
16
+ puts info + "\n\n"
17
+ print " "; sh "gem build #{gemspec_file}"
18
+ FileUtils.mkdir_p 'pkg'
19
+ FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
20
+ puts; sh %{gem install --no-document pkg/#{gemspec.name}-#{gemspec.version}.gem}
21
+ end
22
+
23
+
24
+ # Start an IRB session with the gem loaded
25
+ desc "#{gemspec.name} | IRB"
26
+ task :irb do
27
+ sh "irb -I ./lib -r #{gemspec.name.gsub '-','/'}"
28
+ end
data/bin/stroop ADDED
@@ -0,0 +1,10 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ begin
4
+ require 'stroop'
5
+ rescue LoadError => e
6
+ warn "could not load \"stroop\"\n#{e}"
7
+ exit -1
8
+ end
9
+
10
+ Stroop::CLI.start
data/lib/stroop/cli.rb ADDED
@@ -0,0 +1,42 @@
1
+ require 'thor'
2
+ require_relative 'set'
3
+
4
+ module Stroop
5
+ class CLI < Thor
6
+
7
+ DEFAULT_SIZE = 5.freeze
8
+
9
+ desc 'neutral COLSxROWS', 'prints neutral color words in COLS columns and ROWS rows'
10
+ def neutral(size = '10x5')
11
+ print(size: size, mode: Set::NEUTRAL)
12
+ end
13
+
14
+ desc 'congruent COLSxROWS', 'prints congruent color words in COLS columns and ROWS rows'
15
+ def congruent(size = '10x5')
16
+ print(size: size, mode: Set::CONGRUENT)
17
+ end
18
+
19
+ desc 'incongruent COLSxROWS', 'prints incongruent color words in COLS columns and ROWS rows'
20
+ def incongruent(size = '10x5')
21
+ print(size: size, mode: Set::INCONGRUENT)
22
+ end
23
+
24
+ private
25
+
26
+ def print(size:, mode:)
27
+ rows, columns = dimensions(size)
28
+ rows = apply_default_size(rows)
29
+ columns = apply_default_size(columns)
30
+
31
+ puts Set.new(rows: rows, columns: columns, mode: mode).to_s
32
+ end
33
+
34
+ def dimensions(size)
35
+ size.split('x')
36
+ end
37
+
38
+ def apply_default_size(number)
39
+ number.to_i.zero? ? DEFAULT_SIZE : number.to_i.abs
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,4 @@
1
+ module Stroop
2
+ class Error < StandardError; end
3
+ class SetModeNotAvailable < Error; end
4
+ end
data/lib/stroop/set.rb ADDED
@@ -0,0 +1,95 @@
1
+ require 'colorize'
2
+ require_relative 'exceptions'
3
+
4
+ module Stroop
5
+ class Set
6
+
7
+ COLORS = %w{ black white red green blue yellow }
8
+
9
+ NEUTRAL = :neutral
10
+ CONGRUENT = :congruent
11
+ INCONGRUENT = :incongruent
12
+
13
+ MODES = [NEUTRAL, CONGRUENT, INCONGRUENT].freeze
14
+
15
+ attr_reader :rows, :columns, :mode
16
+
17
+ def initialize(rows:, columns:, mode:)
18
+ raise SetModeNotAvailable.new unless MODES.include?(mode)
19
+
20
+ @rows = rows.to_i.abs
21
+ @columns = columns.to_i.abs
22
+ @mode = mode.to_sym
23
+ end
24
+
25
+ def to_s
26
+ [empty_line, *lines, empty_line].join("\n")
27
+ end
28
+
29
+ private
30
+
31
+ def empty_line
32
+ wrap(space * (total_word_width * columns))
33
+ end
34
+
35
+ def lines
36
+ (1..rows).map { line }
37
+ end
38
+
39
+ def line
40
+ line = (1..columns).map { random_word }.join
41
+ wrap(line)
42
+ end
43
+
44
+ def wrap(line)
45
+ space + line + space
46
+ end
47
+
48
+ def random_word
49
+ word, color = word_color_pair
50
+ word.center(total_word_width).send(color).bold.on_light_black
51
+ end
52
+
53
+ def word_color_pair
54
+ case mode
55
+ when :neutral
56
+ word = random_color
57
+ color = :black
58
+ when :congruent
59
+ word = random_color
60
+ color = word
61
+ when :incongruent
62
+ word, color = random_different_colors
63
+ end
64
+
65
+ [word, color]
66
+ end
67
+
68
+ def random_different_colors
69
+ first = random_color
70
+ second = random_color
71
+
72
+ while first == second
73
+ second = random_color
74
+ end
75
+
76
+ [first, second]
77
+ end
78
+
79
+ def random_color
80
+ COLORS.sample
81
+ end
82
+
83
+ def space
84
+ " ".on_light_black
85
+ end
86
+
87
+ def max_word_length
88
+ @max_word_length ||= COLORS.map { |color| color.chars.count }.max
89
+ end
90
+
91
+ def total_word_width
92
+ max_word_length + 2
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,5 @@
1
+ module Stroop
2
+ VERSION = "0.1.0".freeze
3
+ end
4
+
5
+
data/lib/stroop.rb ADDED
@@ -0,0 +1,6 @@
1
+ require_relative 'stroop/version'
2
+ require_relative 'stroop/set'
3
+ require_relative 'stroop/cli'
4
+
5
+ module Stroop
6
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'stroop'
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Stroop::CLI do
4
+
5
+ before do
6
+ allow_any_instance_of(Stroop::Set).to receive(:to_s) { '' }
7
+ allow($stdout).to receive(:puts) { '' }
8
+ end
9
+
10
+ [:neutral, :congruent, :incongruent].each do |method|
11
+ it { is_expected.to respond_to method }
12
+
13
+ describe "##{method}" do
14
+ let(:size) { '1x1' }
15
+
16
+ it 'should create a new Stroop::Set' do
17
+ expect(Stroop::Set).to receive(:new).once
18
+ subject.send(method, size)
19
+ end
20
+
21
+ it 'should convert the Stroop::Set to a string' do
22
+ expect_any_instance_of(Stroop::Set).to receive(:to_s).once
23
+ subject.send(method, size)
24
+ end
25
+
26
+ it 'should print to the standard output' do
27
+ expect { subject.send(method, size) }.to output.to_stdout
28
+ end
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe Stroop::Set do
4
+
5
+ let(:arguments) { {rows: 1, columns: 2, mode: :neutral } }
6
+ subject { described_class.new(arguments) }
7
+
8
+ describe 'creating a new instance' do
9
+ it 'should raise an error if the given mode is not available' do
10
+ expect {
11
+ described_class.new(arguments.merge({ mode: :not_existing }))
12
+ }.to raise_error Stroop::SetModeNotAvailable
13
+ end
14
+
15
+ it 'should not raise an error if the given mode is available' do
16
+ expect {
17
+ described_class.new(arguments.merge({ mode: :neutral }))
18
+ described_class.new(arguments.merge({ mode: :congruent }))
19
+ described_class.new(arguments.merge({ mode: :incongruent }))
20
+ }.not_to raise_error
21
+ end
22
+ end
23
+
24
+ [:NEUTRAL, :CONGRUENT, :INCONGRUENT, :COLORS, :MODES].each do |name|
25
+ it "should have a constant '#{name}'" do
26
+ expect(described_class.constants).to include name
27
+ end
28
+ end
29
+
30
+ [:rows, :columns, :mode].each do |method|
31
+ it "should respond to ##{method}" do
32
+ expect(subject).to respond_to method
33
+ end
34
+ end
35
+
36
+ it 'should return a text with the instantiated number of lines' do
37
+ actual_rows = subject.to_s.lines.count
38
+ expected_rows = subject.rows + 2 # 2 wrapping empty lines (first & last)
39
+
40
+ expect(actual_rows).to eq expected_rows
41
+ end
42
+
43
+ it 'should return a text with the defined number of words per line' do
44
+ color_regex = /(#{described_class::COLORS.join('|')})/
45
+ line = subject.to_s.lines[1] # first line with words
46
+ words = line.scan(color_regex).flatten
47
+
48
+ expect(words.count).to eq subject.columns
49
+ end
50
+
51
+ end
data/stroop.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + "/lib/stroop/version"
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "stroop"
7
+ gem.version = Stroop::VERSION
8
+ gem.summary = "Stroop effect"
9
+ gem.description = "The Stroop effect - demonstrating the interference in the reaction time of a task."
10
+ gem.authors = ["Paul Götze"]
11
+ gem.email = "paul.christoph.goetze@gmail.com"
12
+ gem.homepage = "https://github.com/paulgoetze/stroop"
13
+ gem.license = "MIT"
14
+
15
+ gem.files = Dir['{**/}{.*,*}'].select{ |path| File.file?(path) && path !~ /^pkg/ }
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ['lib']
19
+
20
+ gem.required_ruby_version = '~> 2.1'
21
+
22
+ gem.add_runtime_dependency 'colorize', '~> 0.7'
23
+ gem.add_runtime_dependency 'thor', '~> 0.19'
24
+
25
+ gem.add_development_dependency 'rspec', '~> 3.0'
26
+ gem.add_development_dependency 'rake', '~> 10.0'
27
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stroop
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Paul Götze
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.19'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.19'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: The Stroop effect - demonstrating the interference in the reaction time
70
+ of a task.
71
+ email: paul.christoph.goetze@gmail.com
72
+ executables:
73
+ - stroop
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - CHANGELOG.md
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - MIT-LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/stroop
87
+ - lib/stroop.rb
88
+ - lib/stroop/cli.rb
89
+ - lib/stroop/exceptions.rb
90
+ - lib/stroop/set.rb
91
+ - lib/stroop/version.rb
92
+ - spec/spec_helper.rb
93
+ - spec/stroop/cli_spec.rb
94
+ - spec/stroop/set_spec.rb
95
+ - stroop.gemspec
96
+ homepage: https://github.com/paulgoetze/stroop
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '2.1'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.4.3
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Stroop effect
120
+ test_files:
121
+ - spec/spec_helper.rb
122
+ - spec/stroop/cli_spec.rb
123
+ - spec/stroop/set_spec.rb