commissioner 0.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 fuJiin
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.
@@ -0,0 +1,17 @@
1
+ = commissioner
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 fuJiin. See LICENSE for details.
@@ -0,0 +1,40 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "commissioner"
8
+ gem.summary = %Q{write in ruby, draw in raphael}
9
+ gem.description = %Q{write in ruby, draw in raphael}
10
+ gem.email = "fu7iin@gmail.com"
11
+ gem.homepage = "http://github.com/fuJiin/commissioner"
12
+ gem.authors = ["fuJiin"]
13
+ gem.add_development_dependency "riot", ">= 0"
14
+ gem.add_dependency "json", ">= 0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ task :test => :check_dependencies
30
+ task :default => :test
31
+
32
+ require 'rake/rdoctask'
33
+ Rake::RDocTask.new do |rdoc|
34
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
35
+
36
+ rdoc.rdoc_dir = 'rdoc'
37
+ rdoc.title = "commissioner #{version}"
38
+ rdoc.rdoc_files.include('README*')
39
+ rdoc.rdoc_files.include('lib/**/*.rb')
40
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0.pre1
@@ -0,0 +1,138 @@
1
+ require 'json'
2
+
3
+ module Commissioner
4
+
5
+ def initialize(type, x = 0, y = 0, options = {})
6
+ eval %W{
7
+ Shapes::#{type.capitalize}.new(x, y, options)
8
+ }
9
+ end
10
+
11
+ class Shapes
12
+ module Raphael
13
+
14
+ OPTIONS = {
15
+
16
+ }
17
+
18
+ def type
19
+ self.class.downcase
20
+ end
21
+
22
+ def normalize(x_array = @x, y_array = @y)
23
+ new_values = {}
24
+
25
+ [x_array, y_array].each_with_index do |array, i|
26
+ max = array.max
27
+ min = array.min
28
+ range = max - min
29
+
30
+ array.each do |value|
31
+ length = i == 0 ? value - min : max - value
32
+ fraction = length / range
33
+ new_values[i] = fraction.to_f
34
+ end
35
+ end
36
+
37
+ clone = self.clone
38
+ clone.x, clone.y = new_values[0], new_values[1]
39
+ return clone
40
+ end
41
+
42
+ def normalize!(x_array = @x, y_array = @y)
43
+ clone = normalize(x_array, y_array)
44
+ self.x, self.y = clone.x, clone.y
45
+ end
46
+
47
+ def normalize_to(context)
48
+ x_array = context.x
49
+ y_array = context.y
50
+ normalize(x_array, y_array)
51
+ end
52
+
53
+ def normalize_to!(context)
54
+ clone = normalize_to(context)
55
+ self.x, self.y = clone.x, clone.y
56
+ end
57
+ end
58
+
59
+ class Path
60
+ include Raphael
61
+ attr_accessor :x, :y, :path_string, :color, :stroke, :stroke_width
62
+
63
+ def initialize(x_array = [], y_array = [], options = {})
64
+ context = options[:context] || nil
65
+ stroke = options[:color] || 'black'
66
+ stroke_width = options[:stroke_width] || 1
67
+ @x = [x_array].flatten
68
+ @y = [y_array].flatten
69
+
70
+ if context
71
+ normalize_to!(context)
72
+ elsif options[:normalize] == true
73
+ normalize!
74
+ end
75
+
76
+ @path_string = create_path_string
77
+ end
78
+
79
+ def create_path_string(x_array = self.x, y_array = self.y)
80
+ string = ''
81
+ [x_array].flatten.each_with_index do |value, i|
82
+ command = i == 0 ? 'M' : 'L'
83
+ string << [command, value, y_array[i]].join(' ')
84
+ end
85
+ return string
86
+ end
87
+
88
+ def commission
89
+ attributes = {
90
+ :type => self.type,
91
+ :path_string => self.path_string
92
+ }
93
+ end
94
+ end
95
+
96
+ class Circle
97
+ include Raphael
98
+ attr_accessor :x, :y, :radius, :stroke, :stroke_width
99
+
100
+ def initialize(x = 0, y = 0, radius = 0, options = {})
101
+ @x = x
102
+ @y = y
103
+ @radius = radius
104
+
105
+ stroke = options[:stroke] || 'black'
106
+ stroke_width = options[:stroke_width] || 1
107
+ context = options[:context]
108
+
109
+ if context
110
+ normalize_to!(context)
111
+ elsif options[:normalize] == true
112
+ normalize!
113
+ end
114
+ end
115
+ end
116
+
117
+ class Text
118
+ include Raphael
119
+ attr_accessor :x, :y, :text
120
+
121
+ def initialize(x = 0, y = 0, text = '')
122
+ if context
123
+ normalize_to!(context)
124
+ elsif options[:normalize] == true
125
+ normalize!
126
+ end
127
+ end
128
+ end
129
+ end
130
+
131
+ class Graph
132
+
133
+ end
134
+
135
+ module Helpers
136
+
137
+ end
138
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'riot'
3
+
4
+ $:<< File.join(File.dirname(__FILE__), '..', 'lib')
5
+ $:<< File.dirname(__FILE__)
6
+
7
+ require 'commissioner'
@@ -0,0 +1,30 @@
1
+ require 'helper'
2
+
3
+ context Commissioner do
4
+
5
+ context '::Raphael' do
6
+
7
+ context '::Path' do
8
+ context 'creating a new Path' do
9
+ setup { Commissioner::Shapes::Path.new( [0, 20, 40, 50], [10, 30, 60, 100] ) }
10
+ asserts('creates an SVG string') { topic.create_path_string.is_a?(String) }
11
+ asserts('properly assigns command') {topic.path_string == 'M 0 10L 20 30L 40 60L 50 100'}
12
+ asserts('assigns attributes') { topic.x && topic.y && topic.path_string }
13
+ end
14
+ end
15
+
16
+ context '::Circle' do
17
+ context 'creating a new cirlce' do
18
+ setup { Commissioner::Shapes::Circle.new(50, 60, 5) }
19
+ asserts('assigns attribtues') { topic.x && topic.y && topic.radius }
20
+ end
21
+ end
22
+
23
+ context '::Text' do
24
+ context 'creating new text' do
25
+
26
+ end
27
+ end
28
+ end
29
+
30
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: commissioner
3
+ version: !ruby/object:Gem::Version
4
+ hash: -2039918859
5
+ prerelease: true
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 0
10
+ - pre1
11
+ version: 0.0.0.pre1
12
+ platform: ruby
13
+ authors:
14
+ - fuJiin
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-06-28 00:00:00 -07:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: riot
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ type: :development
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: json
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ description: write in ruby, draw in raphael
51
+ email: fu7iin@gmail.com
52
+ executables: []
53
+
54
+ extensions: []
55
+
56
+ extra_rdoc_files:
57
+ - LICENSE
58
+ - README.md
59
+ files:
60
+ - .document
61
+ - .gitignore
62
+ - LICENSE
63
+ - Rakefile
64
+ - VERSION
65
+ - lib/commissioner.rb
66
+ - test/helper.rb
67
+ - test/test_commissioner.rb
68
+ - README.md
69
+ has_rdoc: true
70
+ homepage: http://github.com/fuJiin/commissioner
71
+ licenses: []
72
+
73
+ post_install_message:
74
+ rdoc_options:
75
+ - --charset=UTF-8
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ hash: 3
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">"
91
+ - !ruby/object:Gem::Version
92
+ hash: 25
93
+ segments:
94
+ - 1
95
+ - 3
96
+ - 1
97
+ version: 1.3.1
98
+ requirements: []
99
+
100
+ rubyforge_project:
101
+ rubygems_version: 1.3.7
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: write in ruby, draw in raphael
105
+ test_files:
106
+ - test/helper.rb
107
+ - test/test_commissioner.rb