class Dogsay::Dog
Attributes
animal[R]
pose[R]
text_position[R]
Public Class Methods
all(animal=:dog)
click to toggle source
# File lib/dogsay/dog.rb, line 14 def self.all(animal=:dog) find_str = File.join( File.dirname(__FILE__), 'dogs', "*.#{animal}") Dir[find_str].map do |f| File.basename(f, File.extname(f)) end.join ', ' end
all_animals()
click to toggle source
# File lib/dogsay/dog.rb, line 21 def self.all_animals find_str = File.join( File.dirname(__FILE__), 'dogs', '*') Dir[find_str].map do |f| File.extname(f)[1..-1] end.uniq.join ', ' end
new(opts={})
click to toggle source
# File lib/dogsay/dog.rb, line 4 def initialize(opts={}) @animal = opts.fetch :animal @pose = opts.fetch :pose load_yaml end
Public Instance Methods
to_s()
click to toggle source
# File lib/dogsay/dog.rb, line 10 def to_s @ascii end
Private Instance Methods
ascii_from(hash)
click to toggle source
# File lib/dogsay/dog.rb, line 49 def ascii_from(hash) dog_lines = hash[:dog].split("\n") max_length = dog_lines.map(&:length).max dog_lines.map { |l| l.ljust(max_length) }.join("\n") end
filename()
click to toggle source
# File lib/dogsay/dog.rb, line 30 def filename File.join( File.dirname(__FILE__), 'dogs', "#{pose}.#{animal}") end
load_yaml()
click to toggle source
# File lib/dogsay/dog.rb, line 34 def load_yaml begin yaml_hash = YAML.load_file filename rescue Errno::ENOENT begin @pose = :default yaml_hash = YAML.load_file filename rescue Errno::ENOENT raise Dogsay::InvalidDogError.new("Invalid dog file #{filename}") end end @ascii = ascii_from(yaml_hash) @text_position = yaml_hash[:text_position] end