gematria 0.0.4 → 0.0.5
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/CHANGELOG.md +5 -0
- data/README.md +1 -1
- data/lib/gematria.rb +5 -1
- data/lib/gematria/calculator.rb +9 -7
- data/lib/gematria/{tables.rb → table_manager.rb} +27 -34
- data/lib/gematria/version.rb +2 -1
- data/spec/gematria/{tables_spec.rb → table_manager_spec.rb} +14 -20
- data/spec/spec_helper.rb +0 -1
- metadata +5 -5
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v0.0.5
|
|
4
|
+
|
|
5
|
+
* Improved documentation
|
|
6
|
+
* `Gematria::Tables` is now an instance of `Gematria::TableManager` rather than a method bucket
|
|
7
|
+
|
|
3
8
|
## v0.0.4
|
|
4
9
|
|
|
5
10
|
* Ability to set global table so as to not have to specify a table name with every new instance
|
data/README.md
CHANGED
|
@@ -35,7 +35,7 @@ Or install it yourself as:
|
|
|
35
35
|
gematria.converted # => 818
|
|
36
36
|
gematria.mapped # => [7, 5, 40, 1, 200, 90, 9, 1, 0, 9, 100, 0, 6, 300, 50, 0]
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
Setting a global table
|
|
39
39
|
|
|
40
40
|
Gematria::Tables.set_table :hebrew
|
|
41
41
|
alephbet = Gematria::Calculator.new 'אבגדהוזחטיכלמנסעפצקרשתךםןףץ'
|
data/lib/gematria.rb
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
|
2
2
|
require "gematria/version"
|
|
3
|
-
require "gematria/
|
|
3
|
+
require "gematria/table_manager"
|
|
4
4
|
require "gematria/calculator"
|
|
5
5
|
|
|
6
|
+
# A Ruby gem that calculates Gematria
|
|
6
7
|
module Gematria
|
|
8
|
+
# initialize TableManager
|
|
9
|
+
Tables = TableManager.new
|
|
10
|
+
|
|
7
11
|
# Add built-in tables
|
|
8
12
|
|
|
9
13
|
# applies "mispar hechrachi" method to English alphabet (http://www.inner.org/gematria/fourways.php)
|
data/lib/gematria/calculator.rb
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
|
2
2
|
module Gematria
|
|
3
|
+
# Performs the gematria calculations
|
|
3
4
|
class Calculator
|
|
4
5
|
|
|
5
6
|
attr_reader :text, :table
|
|
7
|
+
|
|
8
|
+
# Takes the text to be converted and an optional table name
|
|
9
|
+
# @param text [String] text to be converted
|
|
10
|
+
# @param table_name [Symbol] optional table name to use in conversion. If none is specified, the global will be used (see Gematria::Tables#set_table)
|
|
6
11
|
def initialize(text, table_name=nil)
|
|
7
12
|
@text = text
|
|
8
13
|
if table_name.is_a? Symbol
|
|
@@ -13,20 +18,18 @@ module Gematria
|
|
|
13
18
|
end
|
|
14
19
|
|
|
15
20
|
# Gets an array of the values for each character of text.
|
|
16
|
-
#
|
|
21
|
+
# @example
|
|
17
22
|
# name = Gematria::English.new("Adam")
|
|
18
23
|
# name.mapped # => [1, 4, 1, 40]
|
|
19
|
-
#
|
|
20
24
|
# @return [Array<Number>] numerical values attributed to each character of the original text
|
|
21
25
|
def mapped
|
|
22
26
|
text.each_char.map { |c| lookup_char c }
|
|
23
27
|
end
|
|
24
28
|
|
|
25
29
|
# Gets the summed gematria number of text.
|
|
26
|
-
#
|
|
30
|
+
# @example
|
|
27
31
|
# name = Gematria::English.new("Adam")
|
|
28
32
|
# name.converted # => 46
|
|
29
|
-
#
|
|
30
33
|
# This uses <tt>mapped</tt> internally and sums the results.
|
|
31
34
|
# @return [Number] sum of the values of each character
|
|
32
35
|
def converted
|
|
@@ -34,11 +37,10 @@ module Gematria
|
|
|
34
37
|
end
|
|
35
38
|
|
|
36
39
|
# Recursively reduces the <tt>converted</tt> value to a single digit mispar katan mispari style.
|
|
37
|
-
#
|
|
40
|
+
# @example
|
|
38
41
|
# name = Gematria::English.new("Adam")
|
|
39
42
|
# name.reduced # => 1
|
|
40
|
-
#
|
|
41
|
-
# For example: "Adam" -> 46 -> 10 -> 1
|
|
43
|
+
# # "Adam" -> 46 -> 10 -> 1
|
|
42
44
|
# @return [Number] single digit from reduction of <tt>converted</tt> value
|
|
43
45
|
def reduced
|
|
44
46
|
do_reduction_on converted
|
|
@@ -1,64 +1,57 @@
|
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
|
2
2
|
module Gematria
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
TABLES = {}
|
|
3
|
+
# Manages a set of tables that can be used to do the gematria conversion
|
|
4
|
+
class TableManager
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
attr_reader :tables
|
|
7
|
+
|
|
8
|
+
def initialize
|
|
9
|
+
@tables = {}
|
|
10
|
+
@current = nil
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Sets the current table
|
|
14
|
+
# @example
|
|
15
|
+
# Gematria::Tables.set_table(:english)
|
|
12
16
|
# @param table_name [Symbol] table name
|
|
13
17
|
# @return [Symbol] table name
|
|
14
|
-
def
|
|
18
|
+
def set_table(table_name)
|
|
15
19
|
@current = table_name
|
|
16
20
|
end
|
|
17
21
|
|
|
18
22
|
# Gets the currently selected table
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
# Tables.current # => {'a'=>1,'b'=>2,...}
|
|
22
|
-
#
|
|
23
|
+
# @example After setting the table to <tt>:english</tt> with the <tt>#set_table</tt> method
|
|
24
|
+
# Gematria::Tables.current # => {'a'=>1,'b'=>2,...}
|
|
23
25
|
# @return [Hash{String => Number}]
|
|
24
|
-
def
|
|
26
|
+
def current
|
|
25
27
|
fetch(@current)
|
|
26
28
|
end
|
|
27
29
|
|
|
28
30
|
# Adds a table to the table store. A valid table must be a Hash with single character string keys and numerical values.
|
|
29
31
|
# A table that is not a Hash will raise a TypeError. The table name will be converted to a Symbol.
|
|
30
|
-
#
|
|
31
|
-
#
|
|
32
|
-
#
|
|
32
|
+
# @example
|
|
33
|
+
# Gematria::Tables.add_table :mini_english, 'a' => 1, 'b' => 2, 'c' => 3
|
|
34
|
+
# @raise [TypeError] if table is not a valid Hash
|
|
33
35
|
# @param name [#to_sym] table name
|
|
34
36
|
# @param table [Hash{String => Number}] table of characters pointing to corresponding values
|
|
35
|
-
|
|
37
|
+
# @return [void]
|
|
38
|
+
def add_table(name, table)
|
|
36
39
|
if table.is_a? Hash
|
|
37
|
-
|
|
40
|
+
tables[name.to_sym] = table
|
|
38
41
|
else
|
|
39
42
|
raise TypeError, 'Invalid table format'
|
|
40
43
|
end
|
|
41
44
|
end
|
|
42
45
|
|
|
43
46
|
# Fetches specified table
|
|
44
|
-
#
|
|
45
|
-
#
|
|
46
|
-
#
|
|
47
|
-
# @param key [Symbol] table name as a Symbol
|
|
48
|
-
# @return [Hash{String => Number}]
|
|
49
|
-
def self.fetch(key)
|
|
50
|
-
TABLES.fetch(key, {})
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
# Fetches specified table (delegates to #fetch)
|
|
54
|
-
#
|
|
55
|
-
# Tables[:mini_english] # => {'a'=>1,'b'=>2,'c'=>3}
|
|
56
|
-
#
|
|
47
|
+
# @example
|
|
48
|
+
# Gematria::Tables.fetch(:mini_english) # => {'a'=>1,'b'=>2,'c'=>3}
|
|
57
49
|
# @param key [Symbol] table name as a Symbol
|
|
58
50
|
# @return [Hash{String => Number}]
|
|
59
|
-
def
|
|
60
|
-
fetch(key)
|
|
51
|
+
def fetch(key)
|
|
52
|
+
tables.fetch(key, {})
|
|
61
53
|
end
|
|
54
|
+
alias :[] :fetch
|
|
62
55
|
|
|
63
56
|
end
|
|
64
57
|
end
|
data/lib/gematria/version.rb
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
require 'spec_helper'
|
|
3
3
|
|
|
4
4
|
module Gematria
|
|
5
|
+
describe TableManager do
|
|
5
6
|
|
|
6
|
-
describe Tables do
|
|
7
7
|
it "has a hash to store the tables" do
|
|
8
|
-
expect(Tables
|
|
8
|
+
expect(Tables.tables).to be_a Hash
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
describe "#set_table" do
|
|
@@ -38,7 +38,7 @@ module Gematria
|
|
|
38
38
|
context "when table is valid" do
|
|
39
39
|
it "adds the table to the TABLES store" do
|
|
40
40
|
Tables.add_table :valid, 'a'=>1,'b'=>2
|
|
41
|
-
expect(Tables
|
|
41
|
+
expect(Tables.tables).to include valid: {'a'=>1,'b'=>2}
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
context "when table is invalid" do
|
|
@@ -50,27 +50,21 @@ module Gematria
|
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
%w{fetch []}.each do |method_name|
|
|
54
|
+
describe "##{method_name}" do
|
|
55
|
+
context "when table exists" do
|
|
56
|
+
it "returns the table" do
|
|
57
|
+
Tables.add_table :mytable, 'a'=>1
|
|
58
|
+
expect(Tables.send method_name, :mytable).to eq 'a'=>1
|
|
59
|
+
end
|
|
58
60
|
end
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
context "when table does not exist" do
|
|
62
|
+
it "returns an empty hash" do
|
|
63
|
+
expect(Tables.send method_name, :non_existant_table).to eq({})
|
|
64
|
+
end
|
|
63
65
|
end
|
|
64
66
|
end
|
|
65
67
|
end
|
|
66
68
|
|
|
67
|
-
describe "#[]" do
|
|
68
|
-
it "delegates to #fetch" do
|
|
69
|
-
Tables.should_receive(:fetch).with(:key)
|
|
70
|
-
Tables[:key]
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
69
|
end
|
|
75
|
-
|
|
76
70
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: gematria
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.5
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-02-
|
|
12
|
+
date: 2013-02-28 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rspec
|
|
@@ -64,10 +64,10 @@ files:
|
|
|
64
64
|
- gematria.gemspec
|
|
65
65
|
- lib/gematria.rb
|
|
66
66
|
- lib/gematria/calculator.rb
|
|
67
|
-
- lib/gematria/
|
|
67
|
+
- lib/gematria/table_manager.rb
|
|
68
68
|
- lib/gematria/version.rb
|
|
69
69
|
- spec/gematria/calculator_spec.rb
|
|
70
|
-
- spec/gematria/
|
|
70
|
+
- spec/gematria/table_manager_spec.rb
|
|
71
71
|
- spec/spec_helper.rb
|
|
72
72
|
homepage: http://github.com/adamzaninovich/gematria
|
|
73
73
|
licenses: []
|
|
@@ -95,6 +95,6 @@ specification_version: 3
|
|
|
95
95
|
summary: A Ruby gem that calculates Gematria
|
|
96
96
|
test_files:
|
|
97
97
|
- spec/gematria/calculator_spec.rb
|
|
98
|
-
- spec/gematria/
|
|
98
|
+
- spec/gematria/table_manager_spec.rb
|
|
99
99
|
- spec/spec_helper.rb
|
|
100
100
|
has_rdoc:
|