nairda-ines 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2008 Adrian Pacała
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README ADDED
@@ -0,0 +1,37 @@
1
+ = INES - Inline Narrated Expressions Syntax
2
+
3
+ INES is a quasi-markup language designed to indicate various human
4
+ expressions with plain ASCII characters.
5
+
6
+ It was originally intended to use in my browser-based RPG, so if you ask
7
+ yourself "WTF is this?" - that's ok :)
8
+
9
+ == Quick intro
10
+
11
+ You can embed any text in a pair of tags to mark it as expression. Instead,
12
+ you can prefix the text with that tags, but in this case any leading
13
+ expressions will be ignored.
14
+
15
+ Note that any whitespace surrounding content of every expression is trimmed
16
+ (thus it's an _inline_ markup). Additionaly, every part of the text not
17
+ indicating any expression will be converted to the default one.
18
+
19
+ == Tags
20
+
21
+ By default following tags are available:
22
+
23
+ * ` - statement (default)
24
+ * $ - shout
25
+ * _ - whisper
26
+ * # - thought
27
+ * * - action
28
+
29
+ == Examples
30
+
31
+ *Ines looked happy today.* `I'm alive at last!` *she said.*
32
+
33
+ $Oh hai!$ ** kitteh smiled.
34
+
35
+ __Nobody loves me...
36
+
37
+ * Squirrel took a nap in the box. *
data/TODO ADDED
@@ -0,0 +1 @@
1
+ * TODO: Write XML, YAML, and JSON engines.
@@ -0,0 +1,57 @@
1
+ module INES
2
+ # Class representing INES::Element group in a stack fashion.
3
+ class Collection
4
+ # Creates new INES::Collection object. Any number of +elements+ will be
5
+ # appended to the Collection.
6
+ def initialize(*elements)
7
+ @stack = []
8
+ elements.each { |element| @stack << element if element.is_a?(Element) }
9
+ end
10
+
11
+ # Returns length of the Collection stack.
12
+ def length; @stack.length end
13
+
14
+ # Appends given +element+ to the Collection. Raises ArgumentError if the
15
+ # +element+ is not an Element instance. Returns the Collection itself.
16
+ def add(element)
17
+ raise ArgumentError, 'Argument must be an INES::Element object.' unless element.is_a?(Element)
18
+ @stack << element
19
+ self
20
+ end
21
+
22
+ alias_method :<<, :add
23
+
24
+ # Removes last Element from the stack and returns it.
25
+ def pop; @stack.pop end
26
+
27
+ alias_method :size, :length
28
+
29
+ # Connects any adjacent elements of the same expression type. Returns
30
+ # current Collection.
31
+ def squeeze!
32
+ altered = false
33
+
34
+ @stack.each_index do |i|
35
+ following = @stack[i + 1]
36
+
37
+ if !following.nil? && @stack[i].expression == following.expression
38
+ @stack[i].content << " #{following.content}"
39
+ @stack.delete(following)
40
+ altered = true
41
+ end
42
+ end
43
+
44
+ # If some elements were changed run this method again.
45
+ altered ? squeeze! : self
46
+ end
47
+
48
+ # Returns current stack. Additionally every Element will be yielded if any
49
+ # +block+ is given.
50
+ def stack(&block) #:yields: element
51
+ @stack.each { |e| yield e } if block_given?
52
+ @stack
53
+ end
54
+
55
+ alias_method :each, :stack
56
+ end
57
+ end
@@ -0,0 +1,34 @@
1
+ module INES
2
+ # Class representing an expression Element.
3
+ class Element
4
+ # List of available expressions.
5
+ EXPRESSIONS = [:statement, :shout, :whisper, :thought, :action]
6
+
7
+ # Type of the Element.
8
+ attr_reader :expression
9
+
10
+ # Content (text) of the Element.
11
+ attr_reader :content
12
+
13
+ # Creates new INES::Element object. Optionally takes +exp+ as initial
14
+ #
15
+ # * +con+ - initial content of the Element
16
+ # * +exp+ - expression type of the Element (optional)
17
+ def initialize(con, exp = nil)
18
+ self.content = con
19
+ self.expression = exp || EXPRESSIONS.first
20
+ end
21
+
22
+ # Sets +exp+ as the expression of current Element. If +e+ is not an
23
+ # existing expression type, no changes will be made.
24
+ def expression=(exp)
25
+ @expression = exp unless EXPRESSIONS.index(exp).nil?
26
+ end
27
+
28
+ # Sets +con+ as the content of current Element. Any leading or trailing
29
+ # whitespace will be removed from the content.
30
+ def content=(con)
31
+ @content = con.to_s.strip
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module INES
2
+ VERSION = '0.1.0'
3
+ end
data/lib/ines.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'pathname'
2
+
3
+ INES_ROOT = Pathname(__FILE__).dirname.expand_path + 'ines'
4
+
5
+ require INES_ROOT + 'collection'
6
+ require INES_ROOT + 'element'
7
+ require INES_ROOT + 'engine'
8
+ require INES_ROOT + 'version'
9
+
10
+ module INES #:nodoc:
11
+ end
@@ -0,0 +1,4 @@
1
+ require 'pathname'
2
+ require 'rubygems'
3
+ require 'spec'
4
+ require Pathname(__FILE__).dirname.expand_path.parent + 'lib/ines'
@@ -0,0 +1,54 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
+
3
+ include INES
4
+
5
+ describe Collection do
6
+ before(:each) do
7
+ @collection = Collection.new
8
+ end
9
+
10
+ it 'should create an empty collection' do
11
+ @collection.should be_instance_of(Collection)
12
+ end
13
+
14
+ it 'should create an empty collection when invalid parameters are passed' do
15
+ Collection.new(:foo, :bar).length.should equal(0)
16
+ end
17
+
18
+ it 'should properly count stacked elements' do
19
+ @collection.length.should equal(0)
20
+ end
21
+
22
+ it 'should add and remove new elements from the collection' do
23
+ e = Element.new('Hai!', :statement)
24
+ @collection.add(e).should be_instance_of(Collection)
25
+ @collection.stack.length.should equal(1)
26
+ @collection.pop.should equal(e)
27
+ end
28
+
29
+ it 'should raise error when adding invalid argument' do
30
+ lambda { @collection.add('Nasty!') }.should raise_error(ArgumentError)
31
+ end
32
+
33
+ it 'should squeeze the collection' do
34
+ 3.times { @collection << Element.new('Hai!', :statement) }
35
+ @collection.squeeze!.should be_instance_of(Collection)
36
+ @collection.should have(1).items
37
+ @collection.stack.first.content.should eql('Hai! Hai! Hai!')
38
+ end
39
+
40
+ it 'should return the stack when no block is given' do
41
+ @collection.stack.should have(0).items
42
+ end
43
+
44
+ it 'should yield every stack element when a block is given' do
45
+ e = Element.new 'Im in ur specs, yieldin ur elements.'
46
+ @collection << e << e << e
47
+ @collection.length.should equal(3)
48
+
49
+ # Compare each element.
50
+ @collection.stack do |element|
51
+ element.should equal(e)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,40 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
+
3
+ include INES
4
+
5
+ describe Element do
6
+ before(:each) do
7
+ @element = Element.new('Hai!', :statement)
8
+ end
9
+
10
+ it 'should add and remove new expression type' do
11
+ Element::EXPRESSIONS.push(:foo).should equal(Element::EXPRESSIONS)
12
+ Element::EXPRESSIONS.delete(:foo).should equal(:foo)
13
+ end
14
+
15
+ it 'should create an element' do
16
+ @element.should be_instance_of(Element)
17
+ end
18
+
19
+ it 'should create an element with given parameters' do
20
+ e = Element.new('Oh hai!', :statement)
21
+ e.should be_instance_of(Element)
22
+ e.expression.should equal(:statement)
23
+ e.content.should eql('Oh hai!')
24
+ end
25
+
26
+ it 'should set expression type of the element' do
27
+ @element.expression = :action
28
+ @element.expression.should equal(:action)
29
+ end
30
+
31
+ it 'should not invalid expression type of the element' do
32
+ @element.expression = :foo
33
+ @element.expression.should equal(:statement)
34
+ end
35
+
36
+ it 'should set new content of the element' do
37
+ @element.content = 'Nom! Nom! Nom!'
38
+ @element.content.should eql('Nom! Nom! Nom!')
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nairda-ines
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - "Adrian Paca\xC5\x82a"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-05-20 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: adrian@zenbe.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ - TODO
25
+ - LICENSE
26
+ files:
27
+ - README
28
+ - LICENSE
29
+ - lib/ines/collection.rb
30
+ - lib/ines/element.rb
31
+ - lib/ines/version.rb
32
+ - lib/ines.rb
33
+ - spec/unit/collection_spec.rb
34
+ - spec/unit/element_spec.rb
35
+ - spec/spec_helper.rb
36
+ - TODO
37
+ has_rdoc: true
38
+ homepage: http://github.com/nairda/ines
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --line-numbers
42
+ - --inline-source
43
+ - - --charset
44
+ - utf-8
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ requirements: []
60
+
61
+ rubyforge_project:
62
+ rubygems_version: 1.0.1
63
+ signing_key:
64
+ specification_version: 2
65
+ summary: Inline Narrated Expressions Syntax
66
+ test_files: []
67
+