flames 0.0.1

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.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 [name of plugin creator]
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 ADDED
@@ -0,0 +1,13 @@
1
+ Flames
2
+ ======
3
+
4
+ Introduction goes here.
5
+
6
+
7
+ Example
8
+ =======
9
+
10
+ Example goes here.
11
+
12
+
13
+ Copyright (c) 2010 [name of plugin creator], released under the MIT license
@@ -0,0 +1,52 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ require 'rake/gempackagetask'
5
+
6
+ desc 'Default: run unit tests.'
7
+ task :default => :test
8
+
9
+ desc 'Test the flames plugin.'
10
+ Rake::TestTask.new(:test) do |t|
11
+ t.libs << 'lib'
12
+ t.libs << 'test'
13
+ t.pattern = 'test/**/*_test.rb'
14
+ t.verbose = true
15
+ end
16
+
17
+ desc 'Generate documentation for the flames plugin.'
18
+ Rake::RDocTask.new(:rdoc) do |rdoc|
19
+ rdoc.rdoc_dir = 'rdoc'
20
+ rdoc.title = 'Flames'
21
+ rdoc.options << '--line-numbers' << '--inline-source'
22
+ rdoc.rdoc_files.include('README')
23
+ rdoc.rdoc_files.include('lib/**/*.rb')
24
+ end
25
+
26
+ PKG_FILES = FileList[
27
+ '[a-zA-Z]*',
28
+ 'generators/**/*',
29
+ 'lib/**/*',
30
+ 'rails/**/*',
31
+ 'tasks/**/*',
32
+ 'test/**/*'
33
+ ]
34
+
35
+ spec = Gem::Specification.new do |s|
36
+ s.name = "flames"
37
+ s.version = "0.0.1"
38
+ s.author = "B V Satyaram"
39
+ s.email = "bvsatyaram@gmail.com"
40
+ s.homepage = "http://bvsatyaram.com/"
41
+ s.platform = Gem::Platform::RUBY
42
+ s.summary = "The FLAMES game"
43
+ s.files = PKG_FILES.to_a
44
+ s.require_path = "lib"
45
+ s.has_rdoc = false
46
+ s.extra_rdoc_files = ["README"]
47
+ end
48
+
49
+ desc 'Turn this plugin into a gem.'
50
+ Rake::GemPackageTask.new(spec) do |pkg|
51
+ pkg.gem_spec = spec
52
+ end
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,74 @@
1
+ ################################################################################
2
+ # Flames - Game
3
+ # Author : Satyaram B V
4
+ # Website: http://bvsatyaram.com
5
+ ################################################################################
6
+ class Flames
7
+ FLAMES_STRING = "FLAMES"
8
+ RELATIONS = ["Friends", "Lovers", "Ancestors", "Married", "Enemies", "Sisters"]
9
+
10
+ def self.compute(name1, name2)
11
+ compute_flames(name1, name2)
12
+ end
13
+
14
+ private
15
+
16
+ def self.map_relation_code_to_relation_string(relation_code)
17
+ raise "Invalid relation code" unless ((0..(FLAMES_STRING.length - 1)).to_a).include?(relation_code)
18
+
19
+ return RELATIONS[relation_code]
20
+ end
21
+
22
+ def self.strike_flames(score, relation_codes = (0..(FLAMES_STRING.length - 1)).to_a, offset = 0)
23
+ # Strike flames with the number input
24
+ relation_codes_length = relation_codes.size
25
+ return relation_codes.first if relation_codes_length == 1
26
+
27
+ remainder = ((score + offset) % relation_codes_length)
28
+
29
+ if remainder == 0
30
+ new_offset = relation_codes_length - 1
31
+ else
32
+ new_offset = remainder - 1
33
+ end
34
+ new_codes = []
35
+
36
+ (0..(relation_codes_length - 1)).each do |i|
37
+ new_codes << relation_codes[i] if i != new_offset
38
+ end
39
+
40
+ return strike_flames(score, new_codes, new_offset)
41
+ end
42
+
43
+ def self.get_flames_count(chars1, chars2)
44
+ flames_score = chars1.size + chars2.size
45
+ chars1 = chars1.sort
46
+ chars2 = chars2.sort
47
+ chars1.uniq.each do |char|
48
+ a = chars1.select{|x| x == char}.size
49
+ b = chars2.select{|x| x == char}.size
50
+ flames_score -= 2*[a,b].min
51
+ end
52
+
53
+ flames_score = strike_flames(flames_score)
54
+
55
+ return flames_score
56
+ end
57
+
58
+ def self.clean_name(name)
59
+ return name.downcase.gsub(/( |\.)/, "")
60
+ end
61
+
62
+ def self.compute_relation_code(name1, name2)
63
+ name1 = clean_name(name1)
64
+ name2 = clean_name(name2)
65
+ chars1 = name1.split("")
66
+ chars2 = name2.split("")
67
+
68
+ return get_flames_count(chars1, chars2)
69
+ end
70
+
71
+ def self.compute_flames(name1, name2)
72
+ return map_relation_code_to_relation_string(compute_relation_code(name1, name2))
73
+ end
74
+ end
@@ -0,0 +1 @@
1
+ require 'flames'
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :flames do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,21 @@
1
+ sqlite:
2
+ :adapter: sqlite
3
+ :dbfile: vendor/plugins/flames/test/flames_plugin.sqlite.db
4
+
5
+ sqlite3:
6
+ :adapter: sqlite3
7
+ :dbfile: vendor/plugins/flames/test/flames_plugin.sqlite3.db
8
+
9
+ postgresql:
10
+ :adapter: postgresql
11
+ :username: postgres
12
+ :password: postgres
13
+ :database: flames_plugin_test
14
+ :min_messages: ERROR
15
+
16
+ mysql:
17
+ :adapter: mysql
18
+ :host: localhost
19
+ :username: root
20
+ :password:
21
+ :database: flames_plugin_test
@@ -0,0 +1,95 @@
1
+ # Logfile created on Wed Sep 01 06:58:41 +0530 2010 by logger.rb/22285
2
+ SQL (0.3ms) select sqlite_version(*)
3
+ SQL (0.4ms)  SELECT name
4
+ FROM sqlite_master
5
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
6
+ 
7
+ SQL (1.3ms) CREATE TABLE "flames" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name1" varchar(255), "name2" varchar(255), "result" varchar(255)) 
8
+ SQL (0.3ms)  SELECT name
9
+ FROM sqlite_master
10
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
11
+ 
12
+ SQL (1.1ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
13
+ SQL (1.0ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
14
+ SQL (0.3ms)  SELECT name
15
+ FROM sqlite_master
16
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
17
+ 
18
+ SQL (0.2ms) SELECT version FROM "schema_migrations"
19
+ SQL (1.3ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
20
+ FlamesTest::Flame Load (0.3ms) SELECT * FROM "flames" 
21
+ SQL (0.3ms) select sqlite_version(*)
22
+ SQL (0.8ms)  SELECT name
23
+ FROM sqlite_master
24
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
25
+ 
26
+ SQL (1.4ms) DROP TABLE "flames"
27
+ SQL (1.4ms) CREATE TABLE "flames" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name1" varchar(255), "name2" varchar(255), "result" varchar(255)) 
28
+ SQL (0.4ms)  SELECT name
29
+ FROM sqlite_master
30
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
31
+ 
32
+ SQL (0.3ms) SELECT version FROM "schema_migrations"
33
+ FlamesTest::Flame Load (0.3ms) SELECT * FROM "flames" 
34
+ SQL (0.2ms) SET SQL_AUTO_IS_NULL=0
35
+ SQL (0.3ms) SHOW TABLES
36
+ SQL (115.3ms) CREATE TABLE `flames` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `name1` varchar(255), `name2` varchar(255), `result` varchar(255)) ENGINE=InnoDB
37
+ SQL (0.4ms) SHOW TABLES
38
+ SQL (110.6ms) CREATE TABLE `schema_migrations` (`version` varchar(255) NOT NULL) ENGINE=InnoDB
39
+ SQL (203.8ms) CREATE UNIQUE INDEX `unique_schema_migrations` ON `schema_migrations` (`version`)
40
+ SQL (0.4ms) SHOW TABLES
41
+ SQL (0.4ms) SELECT version FROM `schema_migrations`
42
+ SQL (31.3ms) INSERT INTO `schema_migrations` (version) VALUES ('0')
43
+ FlamesTest::Flame Load (0.3ms) SELECT * FROM `flames` 
44
+ SQL (0.3ms) select sqlite_version(*)
45
+ SQL (0.6ms)  SELECT name
46
+ FROM sqlite_master
47
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
48
+ 
49
+ SQL (1.5ms) DROP TABLE "flames"
50
+ SQL (1.3ms) CREATE TABLE "flames" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name1" varchar(255), "name2" varchar(255), "result" varchar(255)) 
51
+ SQL (0.3ms)  SELECT name
52
+ FROM sqlite_master
53
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
54
+ 
55
+ SQL (0.2ms) SELECT version FROM "schema_migrations"
56
+ FlamesTest::Flame Load (0.3ms) SELECT * FROM "flames" 
57
+ SQL (0.3ms) select sqlite_version(*)
58
+ SQL (0.6ms)  SELECT name
59
+ FROM sqlite_master
60
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
61
+ 
62
+ SQL (1.4ms) DROP TABLE "flames"
63
+ SQL (1.2ms) CREATE TABLE "flames" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name1" varchar(255), "name2" varchar(255), "result" varchar(255)) 
64
+ SQL (0.3ms)  SELECT name
65
+ FROM sqlite_master
66
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
67
+ 
68
+ SQL (0.2ms) SELECT version FROM "schema_migrations"
69
+ FlamesTest::Flame Load (0.4ms) SELECT * FROM "flames" 
70
+ SQL (0.3ms) select sqlite_version(*)
71
+ SQL (0.5ms)  SELECT name
72
+ FROM sqlite_master
73
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
74
+ 
75
+ SQL (1.3ms) DROP TABLE "flames"
76
+ SQL (1.2ms) CREATE TABLE "flames" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name1" varchar(255), "name2" varchar(255), "result" varchar(255)) 
77
+ SQL (0.3ms)  SELECT name
78
+ FROM sqlite_master
79
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
80
+ 
81
+ SQL (0.2ms) SELECT version FROM "schema_migrations"
82
+ FlamesTest::Flame Load (0.3ms) SELECT * FROM "flames" 
83
+ SQL (0.3ms) select sqlite_version(*)
84
+ SQL (1.1ms)  SELECT name
85
+ FROM sqlite_master
86
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
87
+ 
88
+ SQL (2.9ms) DROP TABLE "flames"
89
+ SQL (3.1ms) CREATE TABLE "flames" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name1" varchar(255), "name2" varchar(255), "result" varchar(255)) 
90
+ SQL (0.6ms)  SELECT name
91
+ FROM sqlite_master
92
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
93
+ 
94
+ SQL (0.4ms) SELECT version FROM "schema_migrations"
95
+ FlamesTest::Flame Load (0.3ms) SELECT * FROM "flames" 
@@ -0,0 +1,17 @@
1
+ require 'test_helper'
2
+
3
+ class FlamesTest < Test::Unit::TestCase
4
+ load_schema
5
+
6
+ class Flame < ActiveRecord::Base
7
+ end
8
+
9
+ def test_schema_has_loaded_correctly
10
+ assert_equal [], Flame.all
11
+ end
12
+
13
+ def test_flames_compute
14
+ assert_equal "Ancestors", Flames.compute("satyaram", "soujanya")
15
+ end
16
+
17
+ end
@@ -0,0 +1,7 @@
1
+ ActiveRecord::Schema.define(:version => 0) do
2
+ create_table :flames, :force => true do |t|
3
+ t.string :name1
4
+ t.string :name2
5
+ t.string :result
6
+ end
7
+ end
@@ -0,0 +1,37 @@
1
+ ENV['RAILS_ENV'] = 'test'
2
+ ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '/../../../..'
3
+
4
+ require 'rubygems'
5
+ require 'active_support'
6
+ require 'active_support/test_case'
7
+ require 'test/unit'
8
+ require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config/environment.rb'))
9
+
10
+ def load_schema
11
+ config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
12
+ ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
13
+
14
+ db_adapter = ENV['DB']
15
+
16
+ # no db passed, try one of these fine config-free DBs before bombing.
17
+ db_adapter ||=
18
+ begin
19
+ require 'rubygems'
20
+ require 'sqlite'
21
+ 'sqlite'
22
+ rescue MissingSourceFile
23
+ begin
24
+ require 'sqlite3'
25
+ 'sqlite3'
26
+ rescue MissingSourceFile
27
+ end
28
+ end
29
+
30
+ if db_adapter.nil?
31
+ raise "No DB Adapter selected. Pass the DB= option to pick one, or install Sqlite or Sqlite3."
32
+ end
33
+
34
+ ActiveRecord::Base.establish_connection(config[db_adapter])
35
+ load(File.dirname(__FILE__) + "/schema.rb")
36
+ require File.dirname(__FILE__) + '/../rails/init'
37
+ end
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flames
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - B V Satyaram
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-01 00:00:00 +05:30
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description:
23
+ email: bvsatyaram@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README
30
+ files:
31
+ - install.rb
32
+ - MIT-LICENSE
33
+ - Rakefile
34
+ - README
35
+ - uninstall.rb
36
+ - lib/flames.rb
37
+ - rails/init.rb
38
+ - tasks/flames_tasks.rake
39
+ - test/database.yml
40
+ - test/debug.log
41
+ - test/flames_plugin.sqlite3.db
42
+ - test/flames_test.rb
43
+ - test/schema.rb
44
+ - test/test_helper.rb
45
+ has_rdoc: true
46
+ homepage: http://bvsatyaram.com/
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options: []
51
+
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 3
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ requirements: []
73
+
74
+ rubyforge_project:
75
+ rubygems_version: 1.3.7
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: The FLAMES game
79
+ test_files: []
80
+