class SayItWithGraphs::Framer

Public Class Methods

new() click to toggle source
# File lib/say_it_with_graphs/framer.rb, line 4
def initialize()
  @characters = []
  @mapping = {}
end

Public Instance Methods

frames(sentence) click to toggle source
# File lib/say_it_with_graphs/framer.rb, line 9
def frames(sentence)
  @characters = sentence.split ''
  load_mapping!
  @characters.collect do |char|
    character = char.downcase
    validate! character
    klass_for(character:character).new.draw
  end
end

Private Instance Methods

klass_for(character: char) click to toggle source
# File lib/say_it_with_graphs/framer.rb, line 36
def klass_for(character: char)
  @mapping[character]
end
load_mapping!() click to toggle source
# File lib/say_it_with_graphs/framer.rb, line 21
def load_mapping!
  SayItWithGraphs::Characters.constants.each do |const|
    klass = eval("SayItWithGraphs::Characters::#{const}")
    @mapping[klass.new.define.downcase] = klass
  end
end
valid?(character) click to toggle source
# File lib/say_it_with_graphs/framer.rb, line 32
def valid?(character)
  @mapping.has_key? character.downcase
end
validate!(character) click to toggle source
# File lib/say_it_with_graphs/framer.rb, line 28
def validate!(character)
  fail 'Not supported character!' unless valid? character
end