class ShriftMap
A String that alternates between characters and numbers. Short hand for a collection of variables that hold integer values.
Shrift
map keys are lowercase.
Attributes
schema[R]
shrift_map_string[R]
Public Class Methods
new(shrift_map_string)
click to toggle source
# File lib/shrift/shrift_map.rb, line 11 def initialize(shrift_map_string) @shrift_map_string = shrift_map_string @schema = {} split(shrift_map_string) end
to_shrift_map(hash)
click to toggle source
# File lib/shrift/shrift_map.rb, line 33 def self.to_shrift_map(hash) ShriftMap.new(ShriftMap.to_shrift_map_string(hash)) end
to_shrift_map_string(hash)
click to toggle source
# File lib/shrift/shrift_map.rb, line 37 def self.to_shrift_map_string(hash) hash.map { |key, val| "#{key}#{val}" }.join end
Public Instance Methods
fetch(key)
click to toggle source
# File lib/shrift/shrift_map.rb, line 17 def fetch(key) @schema[key.downcase.to_sym].to_i end
store(key, value)
click to toggle source
# File lib/shrift/shrift_map.rb, line 21 def store(key, value) @schema[key.downcase.to_sym] = value.to_i end
to_hash()
click to toggle source
# File lib/shrift/shrift_map.rb, line 25 def to_hash @schema end
to_s()
click to toggle source
# File lib/shrift/shrift_map.rb, line 29 def to_s @shrift_map_string end
Private Instance Methods
split(shrift_map_string)
click to toggle source
# File lib/shrift/shrift_map.rb, line 43 def split(shrift_map_string) until shrift_map_string.empty? shrift_group = shrift_map_string.scan(/^([a-zA-Z]+)(\d+)(.*)/).first begin store(shrift_group[0], shrift_group[1]) rescue NoMethodError raise ShriftException, "Unbalanced ShriftMap: #{@shrift_map_string}" end shrift_map_string = shrift_group[2] end end