Class: Cowsapi::Cow
- Inherits:
-
Object
- Object
- Cowsapi::Cow
- Defined in:
- lib/cowsapi/cow.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name) ⇒ Cow
constructor
A new instance of Cow.
- #say(string) ⇒ Object
Constructor Details
#initialize(name) ⇒ Cow
Returns a new instance of Cow.
28 29 30 |
# File 'lib/cowsapi/cow.rb', line 28 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
27 28 29 |
# File 'lib/cowsapi/cow.rb', line 27 def name @name end |
Class Method Details
.all ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/cowsapi/cow.rb', line 8 def all puts "getting all cows" lines = `cowsay -l`.split("\n") [DefaultCow.new].tap do |cows| lines[1..-1].each do |line| line.split.each do |c| cows << Cow.new(c) end end end end |
.get(name) ⇒ Object
20 21 22 23 24 |
# File 'lib/cowsapi/cow.rb', line 20 def get(name) all.detect{|cow| cow.name == name } end |
Instance Method Details
#say(string) ⇒ Object
32 33 34 |
# File 'lib/cowsapi/cow.rb', line 32 def say(string) `cowsay -f #{name} #{Shellwords.escape(string)}` end |