interrogative 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem "json"
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "riot", ">= 0"
12
+ gem "yard", "~> 0.7"
13
+ gem "rdoc", "~> 3.12"
14
+ gem "bundler", "~> 1.0.0"
15
+ gem "jeweler", "~> 1.8.3"
16
+ gem "redcarpet"
17
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.8.3)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rdoc
10
+ json (1.6.5)
11
+ rake (0.9.2.2)
12
+ rdoc (3.12)
13
+ json (~> 1.4)
14
+ redcarpet (2.1.0)
15
+ riot (0.12.5)
16
+ rr
17
+ rr (1.0.4)
18
+ yard (0.7.5)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ bundler (~> 1.0.0)
25
+ jeweler (~> 1.8.3)
26
+ json
27
+ rdoc (~> 3.12)
28
+ redcarpet
29
+ riot
30
+ yard (~> 0.7)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Adam Lloyd
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,19 @@
1
+ # interrogative
2
+
3
+ `Interrogative` is a Ruby mixin for curious classes.
4
+
5
+ ## Contributing to interrogative
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ ## Copyright
16
+
17
+ Copyright (c) 2012 Adam Lloyd. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "interrogative"
18
+ gem.homepage = "http://github.com/alloy-d/interrogative"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{A mixin for curious classes.}
21
+ gem.description = <<-EOD
22
+ A simple interface for keeping track of HTML-form-like questions without
23
+ feeling like you're accomodating HTML forms.
24
+ EOD
25
+ gem.email = "alloyd@jibe.com"
26
+ gem.authors = ["Adam Lloyd"]
27
+ # dependencies defined in Gemfile
28
+ end
29
+ Jeweler::RubygemsDotOrgTasks.new
30
+
31
+ require 'rake/testtask'
32
+ Rake::TestTask.new(:test) do |test|
33
+ test.libs << 'lib' << 'test'
34
+ test.pattern = 'test/**/*_test.rb'
35
+ test.verbose = true
36
+ end
37
+
38
+ task :default => :test
39
+
40
+ require 'yard'
41
+ YARD::Rake::YardocTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,70 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "interrogative"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Adam Lloyd"]
12
+ s.date = "2012-02-13"
13
+ s.description = " A simple interface for keeping track of HTML-form-like questions without \n feeling like you're accomodating HTML forms.\n"
14
+ s.email = "alloyd@jibe.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".yardopts",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "interrogative.gemspec",
29
+ "lib/interrogative.rb",
30
+ "lib/interrogative/question.rb",
31
+ "test/interrogative_test.rb",
32
+ "test/teststrap.rb"
33
+ ]
34
+ s.homepage = "http://github.com/alloy-d/interrogative"
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = "1.8.15"
38
+ s.summary = "A mixin for curious classes."
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<json>, [">= 0"])
45
+ s.add_development_dependency(%q<riot>, [">= 0"])
46
+ s.add_development_dependency(%q<yard>, ["~> 0.7"])
47
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
48
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
49
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
50
+ s.add_development_dependency(%q<redcarpet>, [">= 0"])
51
+ else
52
+ s.add_dependency(%q<json>, [">= 0"])
53
+ s.add_dependency(%q<riot>, [">= 0"])
54
+ s.add_dependency(%q<yard>, ["~> 0.7"])
55
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
56
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
57
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
58
+ s.add_dependency(%q<redcarpet>, [">= 0"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<json>, [">= 0"])
62
+ s.add_dependency(%q<riot>, [">= 0"])
63
+ s.add_dependency(%q<yard>, ["~> 0.7"])
64
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
65
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
66
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
67
+ s.add_dependency(%q<redcarpet>, [">= 0"])
68
+ end
69
+ end
70
+
@@ -0,0 +1,42 @@
1
+ require 'interrogative/question'
2
+
3
+ # A mixin for curious classes.
4
+ module Interrogative
5
+ # Get the array of all noted questions.
6
+ #
7
+ # @return [Array<Question>] array of all noted questions.
8
+ def questions; @_questions; end
9
+
10
+ # Give instructions for dealing with new questions.
11
+ #
12
+ # @param [Proc] postprocessor a block to run after adding a question;
13
+ # the question is given as the argument.
14
+ def when_questioned(&postprocessor)
15
+ (@_question_postprocessors||=[]) << postprocessor
16
+ end
17
+
18
+ # Give a new question.
19
+ #
20
+ # @param [Symbol, String] name the name (think <input name=...>) of
21
+ # the question.
22
+ # @param [String] label the text of the question (think <label>).
23
+ # @param [Hash] attrs additional attributes for the question.
24
+ # @option attrs [Boolean] :long whether the question has a long answer
25
+ # (think <textarea> vs <input>).
26
+ # @option attrs [Boolean] :multiple whether the question could have
27
+ # multiple answers.
28
+ # @return [Question] the new Question.
29
+ def question(name, text, attrs={})
30
+ q = Question.new(name, text, self, attrs)
31
+ (@_questions||=[]) << q
32
+
33
+ unless @_question_postprocessors.nil?
34
+ @_question_postprocessors.each do |postprocessor|
35
+ postprocessor.call(q)
36
+ end
37
+ end
38
+
39
+ return q
40
+ end
41
+ end
42
+
@@ -0,0 +1,68 @@
1
+ require 'json'
2
+ require 'yaml'
3
+
4
+ module Interrogative
5
+
6
+ # A question with a unique name and a textual representation.
7
+ #
8
+ # Designed to translate well into an HTML form element without
9
+ # betraying the fact that it's meant to transform into an HTML form
10
+ # element.
11
+ class Question
12
+ attr_accessor :name, :text, :attrs
13
+
14
+ # @see Interrogative#question
15
+ def initialize(name, text, owner=nil, attrs={})
16
+ @name = name or raise ArgumentError, "A question must have a name."
17
+ @text = text or raise ArgumentError, "A question must have a label."
18
+ @owner = owner
19
+ @attrs = attrs
20
+ end
21
+
22
+ # Possible answers for the question.
23
+ #
24
+ # Returns `nil` unless the class that included Interrogative
25
+ # responds to a method called `#{ name }_options`; otherwise, it
26
+ # returns the result of calling that method.
27
+ #
28
+ # Options should be either an Array or a Hash.
29
+ # In the case of a Hash, the format should be `{ text => value }`.
30
+ #
31
+ # @return [Array, Hash] the possible answers for the question.
32
+ def options
33
+ return nil if @owner.nil?
34
+
35
+ options_method = "#{@name}_options".intern
36
+ if @owner.respond_to? options_method
37
+ @owner.send options_method
38
+ end
39
+ end
40
+
41
+ # Returns a hash representation of the question.
42
+ #
43
+ # Attributes are merged into the top level, along with `:text` and
44
+ # `:name`. Possible options are nested under `:options`.
45
+ #
46
+ # @return [Hash]
47
+ def to_hash
48
+ h = @attrs.merge({
49
+ :text => text,
50
+ :name => name,
51
+ })
52
+
53
+ o = options
54
+ h[:options] = o if not o.nil?
55
+ return h
56
+ end
57
+
58
+ # Returns a JSON object created from the question's hash
59
+ # representation.
60
+ #
61
+ # @return [String]
62
+ # @see #to_hash
63
+ def to_json(opts={})
64
+ self.to_hash.to_json(opts)
65
+ end
66
+ end
67
+ end
68
+
@@ -0,0 +1,11 @@
1
+ require 'teststrap'
2
+
3
+ context "interrogative" do
4
+ setup do
5
+ false
6
+ end
7
+
8
+ asserts "i'm a failure :(" do
9
+ topic
10
+ end
11
+ end
data/test/teststrap.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'riot'
11
+ require 'interrogative'
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: interrogative
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Adam Lloyd
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: &70276415456120 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70276415456120
25
+ - !ruby/object:Gem::Dependency
26
+ name: riot
27
+ requirement: &70276415471080 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70276415471080
36
+ - !ruby/object:Gem::Dependency
37
+ name: yard
38
+ requirement: &70276415470480 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '0.7'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70276415470480
47
+ - !ruby/object:Gem::Dependency
48
+ name: rdoc
49
+ requirement: &70276415469800 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.12'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70276415469800
58
+ - !ruby/object:Gem::Dependency
59
+ name: bundler
60
+ requirement: &70276415468960 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 1.0.0
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70276415468960
69
+ - !ruby/object:Gem::Dependency
70
+ name: jeweler
71
+ requirement: &70276415467980 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 1.8.3
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70276415467980
80
+ - !ruby/object:Gem::Dependency
81
+ name: redcarpet
82
+ requirement: &70276415467400 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70276415467400
91
+ description: ! " A simple interface for keeping track of HTML-form-like questions
92
+ without \n feeling like you're accomodating HTML forms.\n"
93
+ email: alloyd@jibe.com
94
+ executables: []
95
+ extensions: []
96
+ extra_rdoc_files:
97
+ - LICENSE.txt
98
+ - README.md
99
+ files:
100
+ - .document
101
+ - .yardopts
102
+ - Gemfile
103
+ - Gemfile.lock
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - VERSION
108
+ - interrogative.gemspec
109
+ - lib/interrogative.rb
110
+ - lib/interrogative/question.rb
111
+ - test/interrogative_test.rb
112
+ - test/teststrap.rb
113
+ homepage: http://github.com/alloy-d/interrogative
114
+ licenses:
115
+ - MIT
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ segments:
127
+ - 0
128
+ hash: 4348943104626374028
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 1.8.15
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: A mixin for curious classes.
141
+ test_files: []