Class: Cow

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_cowsay/cow.rb

Constant Summary collapse

FACE_TYPES =
{
  'default' => ["oo", "  "],
  'borg' => ["==", "  "],
  'dead' => ["==", "U "],
  'greedy' => ["$$", "  "],
  'paranoid' => ["@@", "  "],
  'stoned' => ["**", "U "],
  'tired' => ["--", "  "],
  'wired' => ["OO", "  "],
  'young' => ["..", "  "]
}
MAX_LINE_LENGTH =
36

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Cow

Instance Methods =



22
23
24
25
26
27
28
# File 'lib/ruby_cowsay/cow.rb', line 22

def initialize(options={})
  @cow_type = Cow.cows.include?(options[:cow]) ? options[:cow] : 'default'
  require "#{File.expand_path(File.dirname(__FILE__))}/cows/#{@cow_type}"
  Cow.class_eval 'include CowTemplate'
  @face_type = Cow.faces.include?(options[:face_type]) ? options[:face_type] : 'default'
  set_eyes_and_tongue!
end

Instance Attribute Details

#cow_typeObject

Returns the value of attribute cow_type.



3
4
5
# File 'lib/ruby_cowsay/cow.rb', line 3

def cow_type
  @cow_type
end

#eyesObject

Returns the value of attribute eyes.



3
4
5
# File 'lib/ruby_cowsay/cow.rb', line 3

def eyes
  @eyes
end

#face_typeObject

Returns the value of attribute face_type.



3
4
5
# File 'lib/ruby_cowsay/cow.rb', line 3

def face_type
  @face_type
end

#tongueObject

Returns the value of attribute tongue.



3
4
5
# File 'lib/ruby_cowsay/cow.rb', line 3

def tongue
  @tongue
end

Class Method Details

.cowsObject



55
56
57
# File 'lib/ruby_cowsay/cow.rb', line 55

def self.cows
  Dir.new("#{File.expand_path(File.dirname(__FILE__))}/cows/").entries.inject([]) { |files, cow_file| files << cow_file.gsub('.rb', '') if cow_file =~ /\.rb/; files }
end

.facesObject

Class Methods =



51
52
53
# File 'lib/ruby_cowsay/cow.rb', line 51

def self.faces
  FACE_TYPES.keys.sort
end

.say(message, type = 'default', face = 'default') ⇒ Object



59
60
61
# File 'lib/ruby_cowsay/cow.rb', line 59

def self.say(message, type = 'default', face = 'default')
  Cow.new({ :cow => type, :face_type => face }).say(message)
end

.think(message, type = 'default', face = 'default') ⇒ Object



63
64
65
# File 'lib/ruby_cowsay/cow.rb', line 63

def self.think(message, type = 'default', face = 'default')
  Cow.new({ :cow => type, :face_type => face }).think(message)
end

Instance Method Details

#say(message, balloon_type = 'say') ⇒ Object



30
31
32
# File 'lib/ruby_cowsay/cow.rb', line 30

def say(message, balloon_type = 'say')
  construct_balloon(message, balloon_type) + "\n" + render_cow
end

#set_eyes_and_tongue!Object



38
39
40
# File 'lib/ruby_cowsay/cow.rb', line 38

def set_eyes_and_tongue!
  @eyes, @tongue = construct_face(@face_type)
end

#set_faceObject

Sets the attribute face_type

Parameters:

  • value

    the value to set the attribute face_type to.



42
43
44
# File 'lib/ruby_cowsay/cow.rb', line 42

def face_type=(value)
  @face_type = value
end

#think(message) ⇒ Object



34
35
36
# File 'lib/ruby_cowsay/cow.rb', line 34

def think(message)
  construct_balloon(message, 'think') + "\n" + render_cow
end