verbify 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 86209b7a021c8eb2e33cd3a52d625cf9347b1515
4
+ data.tar.gz: 6e59821b2c585bd643f38a6dc85d06a5793e6416
5
+ SHA512:
6
+ metadata.gz: 701668421884d24cabc59b8305b6aef86e74cde89857dcb621e1b3c6b6446968b3e171a7a3efe557fc913c6aadfb3952df19c0151dd193b802e1a2e0cf090047
7
+ data.tar.gz: b509eaa9ee833a409d97600c9896daae14c06eee067985fa40d883efca39c019be1cb6c6d94c9ecad342f84b3ed654ade48bef2c1fbf204e637eec6fcaba38df
data/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ Copyright (c) 2013 Joe Davis <joe.davis512@gmail.com>
2
+
3
+ Permission to use, copy, modify, and distribute this software for any
4
+ purpose with or without fee is hereby granted, provided that the above
5
+ copyright notice and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
+
@@ -0,0 +1,6 @@
1
+ # Verbify
2
+
3
+ Verbify is a *very* simple command parser for natural-esque languages intended
4
+ to be used in text-based games, as long as you don't mind inaccuracy too much.
5
+
6
+ *TODO*
@@ -0,0 +1,16 @@
1
+ # Copyright (c) 2013 Joe Davis <joe.davis512@gmail.com>
2
+
3
+ # Permission to use, copy, modify, and distribute this software for any
4
+ # purpose with or without fee is hereby granted, provided that the above
5
+ # copyright notice and this permission notice appear in all copies.
6
+
7
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
+ # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
+
15
+ require 'verbify/command_parser'
16
+
@@ -0,0 +1,85 @@
1
+ # Copyright (c) 2013 Joe Davis <joe.davis512@gmail.com>
2
+
3
+ # Permission to use, copy, modify, and distribute this software for any
4
+ # purpose with or without fee is hereby granted, provided that the above
5
+ # copyright notice and this permission notice appear in all copies.
6
+
7
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
+ # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
+
15
+ module Verbify
16
+
17
+ class CommandParser
18
+ def initialize
19
+ @actions = { nil => { :proc => proc {} } }
20
+ @ignorable = []
21
+ @separators = []
22
+ @error_proc = proc { puts "Invalid" }
23
+ yield self if block_given?
24
+ end
25
+
26
+ def ignore(ignore)
27
+ @ignorable += [*ignore]
28
+ end
29
+
30
+ def split_by(seps)
31
+ @separators += [*seps]
32
+ end
33
+
34
+ def on(possible_verbs, modifiers=[], &block)
35
+ [*possible_verbs].each do |v|
36
+ @actions[v] = { :proc => block, :modifiers => modifiers }
37
+ end
38
+ end
39
+
40
+ def else(&block)
41
+ @error_proc = block
42
+ end
43
+
44
+ def exec!(input)
45
+ words = input.downcase.split.delete_if { |word| @ignorable.include? word }
46
+ commands = []
47
+
48
+ loop do
49
+ commands << words.take_while { |word| not @separators.include? word }
50
+ sep = words.index { |word| @separators.include? word }
51
+ break if sep.nil?
52
+ words = words.drop(sep + 1)
53
+ end
54
+
55
+ commands.each { |args| exec_command! args }
56
+ end
57
+
58
+ private
59
+
60
+ def exec_command!(args)
61
+ verb = args.shift
62
+ action = @actions[verb]
63
+ unless action.nil?
64
+ if action[:modifiers]
65
+ mod = accept_modifiers action[:modifiers], args
66
+ action[:proc].call verb, mod, *args
67
+ else
68
+ action[:proc].call verb, *args
69
+ end
70
+ else
71
+ @error_proc.call verb, *args
72
+ end
73
+ end
74
+
75
+ def accept_modifiers(mods, args)
76
+ mods.include?(args[0]) ? args.shift : nil
77
+ end
78
+
79
+ def setup_scope(block)
80
+ eval(BLOCK_HELPERS, block.binding)
81
+ block
82
+ end
83
+ end
84
+ end
85
+
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: verbify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Joe Davis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Verbify is a *very* simple command parser for natural-esque languages
14
+ intended to be used in text-based games, as long as you don't mind inaccuracy too
15
+ much
16
+ email: joe.davis512@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/verbify/command_parser.rb
22
+ - lib/verbify.rb
23
+ - LICENSE
24
+ - README.md
25
+ homepage: https://github.com/joedavis/verbify
26
+ licenses:
27
+ - ISC
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.0.14
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Command Parser for Text-Based games
49
+ test_files: []