Skip to content

Instantly share code, notes, and snippets.

@spllr
Created February 5, 2012 23:06
Show Gist options
  • Save spllr/1748327 to your computer and use it in GitHub Desktop.
Save spllr/1748327 to your computer and use it in GitHub Desktop.
Calculate your number according to Numerology
#
# Calculate your number according to http://www.astrology.com/what-numerology/2-d-d-66854
#
#
# HOW ARE NUMEROLOGY CALCULATIONS DONE
# In numerology, all numbers are reduced to the single digits 1 through 9 except the special master numbers 11 and 22. 1, 2, 3, 4, 5, 6, 7, 8, 9, 11 and 22 represent the major vibration rates associated with people’s characteristics.
# The numbers are reduced by simple addition. The number 15, for instance, is reduced by adding 1 + 5 to get 6. Similarly, the number 1974 can be reduced by adding 1 + 9 + 7 + 4 to get 21. The 21 can be further reduced by adding 2 + 1 to get 3.
# Letters in individuals’ names are converted to numbers and then added together. These numbers, in turn, are also reduced. The letter A, for instance, is 1; the letter B is 2; the letter C is 3, and so forth. The following table shows the numbers assigned to all 26 letters in the English alphabet.
#
# 1 2 3 4 5 6 7 8 9
# A B C D E F G H I
# J K L M N O P Q R
# S T U V W X Y Z
#
# NOTE:
# You will need the sinatra and haml gem
# %> gem install haml sinatra
#
# USAGE:
# ruby numerology.rb
#
ENV['RACK_ENV'] ||= 'production'
require "sinatra"
require "haml"
helpers do
# Reduces the number to 1 to 9 or 22 or 11
#
def reduce_number(number)
until number == 22 || number == 11 || number <= 9
number = number.to_s.split("").map(&:to_i).inject(:+)
end
number
end
# The returns the value of the word
#
def value_for_word(word)
letters = word.upcase.split("").reject{ |v| v == " "}
letters.map { |l| number_for_letter(l) }.inject(:+)
end
# Returns the corresponding number for letter
#
def number_for_letter(letter)
letter_value_table[letter]
end
# Based on table
#
# 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
# A | B | C | D | E | F | G | H | I
# J | K | L | M | N | O | P | Q | R
# S | T | U | V | W | X | Y | Z
#
def letter_value_table
return @table if @table
@table = {}
('A'..'Z').to_a.each_with_index do |l,i|
@table[l] = i%9 + 1
end
return @table
end
end
get '/' do
haml :index
end
post '/calculate' do
@name = params[:name]
@word_value = value_for_word(@name)
@reduced_value = reduce_number(@word_value)
haml :calculate
end
__END__
@@index
%h1
Numerology
%form{ :action => "/calculate", :method => :post }
%label{ :for => :name }
Your Name
%input{ :type => :text, :name => :name, :id => :name }
%button{ :type => :submit }
Calculate Number
@@calculate
=haml :index, :layout => false
.result
Your the number for #{@name} is #{@word_value}
.result
That gives us the number #{@reduced_value}
@@layout
!!!
%html
%head
%title
Numerology - Calculate Your Number
%body
#page
=yield
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment