gematria 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,13 +1,10 @@
1
1
  ---
2
2
  language: ruby
3
3
  rvm:
4
- - 1.8.7
5
4
  - 1.9.2
6
5
  - 1.9.3
7
6
  - 2.0.0
8
- - rbx-18mode
9
7
  - rbx-19mode
10
- - jruby-18mode
11
8
  - jruby-19mode
12
9
  - jruby-head
13
10
  - ruby-head
data/CHANGELOG.md CHANGED
@@ -1,21 +1,17 @@
1
- ## v0.0.4 (far future)
1
+ # Changelog
2
2
 
3
- ### Todo
3
+ ## v0.0.3
4
4
 
5
- * Pluggable/Configurable correspondence tables
6
- * Pluggable languages (DSL for new languages?)
7
-
8
- ## v0.0.3 (near future)
9
-
10
- ### Todo
11
-
12
- * Make correspondence table into its own object
13
- * Investigate feasability and worth of supporting Hebrew gematria
5
+ * Removes support for 1.8.7 (due to encoding problems with Hebrew) (Now compatible with 1.9.2 - head)
6
+ * Adds Hebrew to built-in tables (now includes English and Hebrew)
7
+ * Adds support for custom tables
8
+ * Requires specifying a table when instantiating
9
+ * Changes api to use Gematria::Calculator (this may still not be stable)
14
10
 
15
11
  ## v0.0.2
16
12
 
17
- * Ruby 1.8.7 compatible
13
+ * Ruby 1.8.7 compatible (Now compatible with 1.8.7 - head)
18
14
 
19
15
  ## v0.0.1
20
16
 
21
- * initial release
17
+ * initial release
data/README.md CHANGED
@@ -1,12 +1,10 @@
1
- # Gematria [![Build Status](https://travis-ci.org/adamzaninovich/gematria.png?branch=master)](https://travis-ci.org/adamzaninovich/gematria)
1
+ # Gematria (גימטריא) [![Build Status](https://travis-ci.org/adamzaninovich/gematria.png?branch=master)](https://travis-ci.org/adamzaninovich/gematria)
2
2
 
3
- A Ruby gem that calculates Gematria. This version supports English text and uses a mispar hechrachi style correspondence table, but in future versions there may be support for more languages as well as user configurable correspondence tables. The gem supports raw conversion to number (by simple summation), mapping (breakdown of individual numbers), and reduction to a single digit (mispar katan mispari).
3
+ A Ruby gem that calculates Gematria. The gem comes with built-in correspondence tables for English and Hebrew text, but allows for user-configurable tables. The gem supports raw conversion to number (by simple summation), mapping (breakdown of individual numbers), and reduction to a single digit (mispar katan mispari).
4
4
 
5
- The current correspondence table is as follows:
5
+ The included correspondence tables are as follows:
6
6
 
7
- a:1 b:2 c:3 d:4 e:5 f:6 g:7 h:8 i:9
8
- j:10 k:20 l:30 m:40 n:50 o:60 p:70 q:80 r:90
9
- s:100 t:200 u:300 v:400 w:500 x:600 y:700 z:800
7
+ ![Correspondence Tables](https://dl.dropbox.com/u/2436753/github/gematria/correspondence_tables.png)
10
8
 
11
9
  ## Documentation
12
10
 
@@ -28,17 +26,29 @@ Or install it yourself as:
28
26
 
29
27
  ## Usage
30
28
 
31
- name = Gematria::English.new("Adam")
29
+ name = Gematria::Calculator.new("Adam", :english)
32
30
  name.converted # => 46
33
31
  name.mapped.join(" + ") # => "1 + 4 + 1 + 40"
34
32
  name.reduced # => 1
35
33
 
36
- gematria = Gematria::English.new("Gematria is fun!")
34
+ gematria = Gematria::Calculator.new("Gematria is fun!", english)
37
35
  gematria.converted # => 818
38
36
  gematria.mapped # => [7, 5, 40, 1, 200, 90, 9, 1, 0, 9, 100, 0, 6, 300, 50, 0]
39
37
 
40
- alphabet = Gematria::English.new("abcdefghijklmnopqrstuvwxyz")
41
- alphabet.converted == 4095 # => true
38
+ alephbet = Gematria::Calculator.new('אבגדהוזחטיכלמנסעפצקרשתךםןףץ', :hebrew)
39
+ alephbet.converted == 4995 # => true
40
+
41
+ # defining a custom table
42
+
43
+ Gematria::Tables.add_table :mini, 'a' => 1, 'b' => 10, 'c' => 100
44
+ abcd = Gematria::Calculator.new('abcd', :mini)
45
+ abcd.mapped # => [1,10,100,0]
46
+ abcd.converted # => 111
47
+ abcd.reduced # => 3
48
+
49
+ ## Issues
50
+
51
+ If you find any issues or errors with this gem, please report them on [Github Issues](http://github.com/adamzaninovich/gematria/issues).
42
52
 
43
53
  ## Contributing
44
54
 
data/ROADMAP.md ADDED
@@ -0,0 +1,9 @@
1
+ # Roadmap
2
+
3
+ ## Near future
4
+
5
+ * Ability to configure global default table so as to not have to specify a table name with every new instance
6
+
7
+ ## Far future
8
+
9
+ * Nothing for now. [Suggestions](http://github.com/adamzaninovich/gematria/issues) are welcome and encouraged.
data/Rakefile CHANGED
@@ -3,4 +3,4 @@ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
data/gematria.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
8
8
  gem.version = Gematria::VERSION
9
9
  gem.authors = ["Adam Zaninovich"]
10
10
  gem.email = ["adam.zaninovich@gmail.com"]
11
- gem.description = %q{A Ruby gem that calculates Gematria. This version supports English text and uses a mispar hechrachi style correspondence table, but in future versions there may be support for more languages as well as user configurable correspondence tables. The gem supports raw conversion to number (by simple summation), mapping (breakdown of individual numbers), and reduction to a single digit (mispar katan mispari).}
11
+ gem.description = %q{A Ruby gem that calculates Gematria. The gem comes with built-in correspondence tables for English and Hebrew text, but allows for user-configurable tables. The gem supports raw conversion to number (by simple summation), mapping (breakdown of individual numbers), and reduction to a single digit (mispar katan mispari).}
12
12
  gem.summary = %q{A Ruby gem that calculates Gematria}
13
13
  gem.homepage = "http://github.com/adamzaninovich/gematria"
14
14
 
data/lib/gematria.rb CHANGED
@@ -1,5 +1,22 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  require "gematria/version"
2
- require "gematria/english"
3
+ require "gematria/tables"
4
+ require "gematria/calculator"
3
5
 
4
6
  module Gematria
5
- end
7
+ # Add built-in tables
8
+
9
+ # applies "mispar hechrachi" method to English alphabet (http://www.inner.org/gematria/fourways.php)
10
+ Tables.add_table :english, {
11
+ 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6, 'g' => 7, 'h' => 8, 'i' => 9,
12
+ 'j' => 10, 'k' => 20, 'l' => 30, 'm' => 40, 'n' => 50, 'o' => 60, 'p' => 70, 'q' => 80, 'r' => 90,
13
+ 's' => 100, 't' => 200, 'u' => 300, 'v' => 400, 'w' => 500, 'x' => 600, 'y' => 700, 'z' => 800
14
+ }
15
+
16
+ # Mispar gadol table
17
+ Tables.add_table :hebrew, {
18
+ 'א' => 1, 'ב' => 2, 'ג' => 3, 'ד' => 4, 'ה' => 5, 'ו' => 6, 'ז' => 7, 'ח' => 8, 'ט' => 9,
19
+ 'י' => 10, 'כ' => 20, 'ל' => 30, 'מ' => 40, 'נ' => 50, 'ס' => 60, 'ע' => 70, 'פ' => 80, 'צ' => 90,
20
+ 'ק' => 100, 'ר' => 200, 'ש' => 300, 'ת' => 400, 'ך' => 500, 'ם' => 600, 'ן' => 700, 'ף' => 800, 'ץ' => 900
21
+ }
22
+ end
@@ -1,11 +1,16 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  module Gematria
2
- class English < Struct.new(:text)
3
- # applies "mispar hechrachi" method to English alphabet (http://www.inner.org/gematria/fourways.php)
4
- CORRESPONDENCE_TABLE = {
5
- :a => 1, :b => 2, :c => 3, :d => 4, :e => 5, :f => 6, :g => 7, :h => 8, :i => 9,
6
- :j => 10, :k => 20, :l => 30, :m => 40, :n => 50, :o => 60, :p => 70, :q => 80, :r => 90,
7
- :s => 100, :t => 200, :u => 300, :v => 400, :w => 500, :x => 600, :y => 700, :z => 800
8
- }
3
+ class Calculator
4
+
5
+ attr_reader :text, :table
6
+ def initialize(text, table_name=nil)
7
+ @text = text
8
+ if table_name.is_a? Symbol
9
+ @table = Tables.fetch(table_name)
10
+ else
11
+ @table = {}
12
+ end
13
+ end
9
14
 
10
15
  # Gets an array of the values for each character of text.
11
16
  #
@@ -40,8 +45,9 @@ module Gematria
40
45
  end
41
46
 
42
47
  private
48
+
43
49
  def lookup_char(char)
44
- CORRESPONDENCE_TABLE.fetch(char.downcase.to_sym, 0)
50
+ table.fetch(char.downcase, 0)
45
51
  end
46
52
 
47
53
  def do_reduction_on(number)
@@ -53,4 +59,4 @@ module Gematria
53
59
  end
54
60
 
55
61
  end
56
- end
62
+ end
@@ -0,0 +1,44 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Gematria
3
+ module Tables
4
+ TABLES = {}
5
+
6
+ module_function
7
+
8
+ # Adds a table to the table store. A valid table must be a Hash with single character string keys and numerical values.
9
+ # A table that is not a Hash will raise a TypeError. The table name will be converted to a Symbol.
10
+ #
11
+ # Tables.add_table :mini_english, 'a' => 1, 'b' => 2, 'c' => 3
12
+ #
13
+ # @param name [#to_sym] table name
14
+ # @param table [Hash{String => Number}] table of characters pointing to corresponding values
15
+ def add_table(name, table)
16
+ if table.is_a? Hash
17
+ TABLES[name.to_sym] = table
18
+ else
19
+ raise TypeError, 'Invalid table format'
20
+ end
21
+ end
22
+
23
+ # Fetches specified table
24
+ #
25
+ # Tables.fetch(:mini_english) # => {'a'=>1,'b'=>2,'c'=>3}
26
+ #
27
+ # @param key [Symbol] table name as a Symbol
28
+ # @return [Hash{String => Number}]
29
+ def fetch(key)
30
+ TABLES.fetch(key)
31
+ end
32
+
33
+ # Fetches specified table (delegates to #fetch)
34
+ #
35
+ # Tables[:mini_english] # => {'a'=>1,'b'=>2,'c'=>3}
36
+ #
37
+ # @param key [Symbol] table name as a Symbol
38
+ # @return [Hash{String => Number}]
39
+ def [](key)
40
+ fetch(key)
41
+ end
42
+
43
+ end
44
+ end
@@ -1,3 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  module Gematria
2
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
3
4
  end
@@ -0,0 +1,95 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Gematria::Calculator do
5
+ describe "with no table specified" do
6
+ it "is instantiated with text and provides access to that text" do
7
+ gematria = Gematria::Calculator.new('mytext')
8
+ expect(gematria.text).to eq 'mytext'
9
+ end
10
+
11
+ describe "#mapped" do
12
+ it "returns an array of values for each character in text" do
13
+ gematria = Gematria::Calculator.new('abc')
14
+ expect(gematria.mapped).to eq [0,0,0]
15
+ end
16
+ end
17
+
18
+ describe "#converted" do
19
+ it "returns the sum of the letter values" do
20
+ gematria = Gematria::Calculator.new('abc')
21
+ expect(gematria.converted).to eq 0
22
+ end
23
+ end
24
+
25
+ describe "#reduced" do
26
+ it "returns a single digit" do
27
+ gematria = Gematria::Calculator.new('abc')
28
+ expect(gematria.reduced).to eq 0
29
+ end
30
+ end
31
+ end
32
+
33
+ describe "with English table specified" do
34
+ describe "#mapped" do
35
+ it "returns an array of values for each character in text" do
36
+ gematria = Gematria::Calculator.new('abc', :english)
37
+ expect(gematria.mapped).to eq [1,2,3]
38
+ end
39
+ end
40
+
41
+ describe "#converted" do
42
+ it "returns the sum of the letter values" do
43
+ gematria = Gematria::Calculator.new('abc', :english)
44
+ expect(gematria.converted).to eq 6
45
+ end
46
+ end
47
+
48
+ describe "#reduced" do
49
+ context "when converted value is a single digit" do
50
+ it "returns a single digit" do
51
+ gematria = Gematria::Calculator.new('abc', :english)
52
+ expect(gematria.reduced).to eq 6
53
+ end
54
+ end
55
+ context "when converted value is more than one digit" do
56
+ it "returns a single digit" do
57
+ gematria = Gematria::Calculator.new('abcdefghijklmnopqrstuvwxyz', :english)
58
+ expect(gematria.reduced).to eq 9 # 4095 -> 18 -> 9
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ describe "with Hebrew table specified" do
65
+ describe "#mapped" do
66
+ it "returns an array of values for each character in text" do
67
+ abg = Gematria::Calculator.new('אבג', :hebrew)
68
+ expect(abg.mapped).to eq [1,2,3]
69
+ end
70
+ end
71
+
72
+ describe "#converted" do
73
+ it "returns the sum of the letter values" do
74
+ alephbet = Gematria::Calculator.new('אבגדהוזחטיכלמנסעפצקרשתךםןףץ', :hebrew)
75
+ expect(alephbet.converted).to eq 4995
76
+ end
77
+ end
78
+
79
+ describe "#reduced" do
80
+ context "when converted value is a single digit" do
81
+ it "returns a single digit" do
82
+ abg = Gematria::Calculator.new('אבג', :hebrew)
83
+ expect(abg.reduced).to eq 6
84
+ end
85
+ end
86
+ context "when converted value is more than one digit" do
87
+ it "returns a single digit" do
88
+ alephbet = Gematria::Calculator.new('אבגדהוזחטיכלמנסעפצקרשתךםןףץ', :hebrew)
89
+ expect(alephbet.reduced).to eq 9 # 4995 -> 27 -> 9
90
+ end
91
+ end
92
+ end
93
+ end
94
+
95
+ end
@@ -0,0 +1,48 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Gematria::Tables do
5
+ it "has a hash to store the tables" do
6
+ expect(Gematria::Tables::TABLES).to be_a Hash
7
+ end
8
+
9
+ describe "#add_table" do
10
+ context "when table is valid" do
11
+ it "adds the table to the TABLES store" do
12
+ Gematria::Tables.add_table :valid, 'a'=>1,'b'=>2
13
+ expect(Gematria::Tables::TABLES).to include valid: {'a'=>1,'b'=>2}
14
+ end
15
+ end
16
+ context "when table is invalid" do
17
+ it "raises a TypeError" do
18
+ expect {
19
+ Gematria::Tables.add_table :invalid, [['a',1],['b',2]]
20
+ }.to raise_error TypeError
21
+ end
22
+ end
23
+ end
24
+
25
+ describe "#fetch" do
26
+ context "when table exists" do
27
+ it "returns the table" do
28
+ Gematria::Tables.add_table :mytable, 'a'=>1
29
+ expect(Gematria::Tables.fetch(:mytable)).to eq 'a'=>1
30
+ end
31
+ end
32
+ context "when table does not exist" do
33
+ it "raises a KeyError" do
34
+ expect {
35
+ Gematria::Tables.fetch(:non_existant_table)
36
+ }.to raise_error KeyError
37
+ end
38
+ end
39
+ end
40
+
41
+ describe "#[]" do
42
+ it "delegates to #fetch" do
43
+ Gematria::Tables.should_receive(:fetch).with(:key)
44
+ Gematria::Tables[:key]
45
+ end
46
+ end
47
+
48
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'rubygems'
1
3
  require 'rspec'
2
4
  require 'gematria'
metadata CHANGED
@@ -1,99 +1,100 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: gematria
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 2
9
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Adam Zaninovich
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2013-02-26 00:00:00 -08:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2013-02-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: rspec
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- version: "0"
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
30
22
  type: :development
31
- version_requirements: *id001
32
- - !ruby/object:Gem::Dependency
33
- name: rake
34
23
  prerelease: false
35
- requirement: &id002 !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- segments:
40
- - 0
41
- version: "0"
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
42
38
  type: :development
43
- version_requirements: *id002
44
- description: A Ruby gem that calculates Gematria. This version supports English text and uses a mispar hechrachi style correspondence table, but in future versions there may be support for more languages as well as user configurable correspondence tables. The gem supports raw conversion to number (by simple summation), mapping (breakdown of individual numbers), and reduction to a single digit (mispar katan mispari).
45
- email:
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: A Ruby gem that calculates Gematria. The gem comes with built-in correspondence
47
+ tables for English and Hebrew text, but allows for user-configurable tables. The
48
+ gem supports raw conversion to number (by simple summation), mapping (breakdown
49
+ of individual numbers), and reduction to a single digit (mispar katan mispari).
50
+ email:
46
51
  - adam.zaninovich@gmail.com
47
52
  executables: []
48
-
49
53
  extensions: []
50
-
51
54
  extra_rdoc_files: []
52
-
53
- files:
55
+ files:
54
56
  - .gitignore
55
57
  - .travis.yml
56
58
  - CHANGELOG.md
57
59
  - Gemfile
58
60
  - LICENSE.txt
59
61
  - README.md
62
+ - ROADMAP.md
60
63
  - Rakefile
61
64
  - gematria.gemspec
62
65
  - lib/gematria.rb
63
- - lib/gematria/english.rb
66
+ - lib/gematria/calculator.rb
67
+ - lib/gematria/tables.rb
64
68
  - lib/gematria/version.rb
65
- - spec/gematria/english_spec.rb
69
+ - spec/gematria/calculator_spec.rb
70
+ - spec/gematria/tables_spec.rb
66
71
  - spec/spec_helper.rb
67
- has_rdoc: true
68
72
  homepage: http://github.com/adamzaninovich/gematria
69
73
  licenses: []
70
-
71
74
  post_install_message:
72
75
  rdoc_options: []
73
-
74
- require_paths:
76
+ require_paths:
75
77
  - lib
76
- required_ruby_version: !ruby/object:Gem::Requirement
77
- requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- segments:
81
- - 0
82
- version: "0"
83
- required_rubygems_version: !ruby/object:Gem::Requirement
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- segments:
88
- - 0
89
- version: "0"
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
90
  requirements: []
91
-
92
91
  rubyforge_project:
93
- rubygems_version: 1.3.6
92
+ rubygems_version: 1.8.24
94
93
  signing_key:
95
94
  specification_version: 3
96
95
  summary: A Ruby gem that calculates Gematria
97
- test_files:
98
- - spec/gematria/english_spec.rb
96
+ test_files:
97
+ - spec/gematria/calculator_spec.rb
98
+ - spec/gematria/tables_spec.rb
99
99
  - spec/spec_helper.rb
100
+ has_rdoc:
@@ -1,37 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Gematria::English do
4
- it "is instantiated with text and provides access to that text" do
5
- gematria = Gematria::English.new('mytext')
6
- expect(gematria.text).to eq 'mytext'
7
- end
8
-
9
- describe "#mapped" do
10
- it "returns an array of values for each character in text" do
11
- gematria = Gematria::English.new('abc')
12
- expect(gematria.mapped).to eq [1,2,3]
13
- end
14
- end
15
-
16
- describe "#converted" do
17
- it "returns the sum of the letter values" do
18
- gematria = Gematria::English.new('abc')
19
- expect(gematria.converted).to eq 6
20
- end
21
- end
22
-
23
- describe "#reduced" do
24
- context "when converted value is a single digit" do
25
- it "returns a single digit" do
26
- gematria = Gematria::English.new('abc')
27
- expect(gematria.reduced).to eq 6
28
- end
29
- end
30
- context "when converted value is more than one digit" do
31
- it "returns a single digit" do
32
- gematria = Gematria::English.new('abcdefghijklmnopqrstuvwxyz')
33
- expect(gematria.reduced).to eq 9 # 4095 -> 18 -> 9
34
- end
35
- end
36
- end
37
- end