Class: StarWarsComics::Artist
- Inherits:
-
Object
- Object
- StarWarsComics::Artist
- Extended by:
- Concerns::Findable
- Defined in:
- lib/star-wars-comics/artist.rb
Direct Known Subclasses
StarWarsComics::Artists::Colorist, StarWarsComics::Artists::Letterer, StarWarsComics::Artists::Penciller, StarWarsComics::Artists::Writer
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#issues ⇒ Object
Returns the value of attribute issues.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #add_issue(issue) ⇒ Object
- #frequent_collaborators ⇒ Object
-
#initialize(name = "", path = "") ⇒ Artist
constructor
A new instance of Artist.
Methods included from Concerns::Findable
find, find_by_name, find_or_create_by_name
Constructor Details
#initialize(name = "", path = "") ⇒ Artist
Returns a new instance of Artist.
8 9 10 11 12 13 |
# File 'lib/star-wars-comics/artist.rb', line 8 def initialize(name = "", path = "") @name = name @path = path @issues = [] @@all << self end |
Instance Attribute Details
#issues ⇒ Object
Returns the value of attribute issues.
4 5 6 |
# File 'lib/star-wars-comics/artist.rb', line 4 def issues @issues end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/star-wars-comics/artist.rb', line 4 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'lib/star-wars-comics/artist.rb', line 4 def path @path end |
Class Method Details
.all ⇒ Object
61 62 63 |
# File 'lib/star-wars-comics/artist.rb', line 61 def self.all @@all end |
.sort_alpha ⇒ Object
57 58 59 |
# File 'lib/star-wars-comics/artist.rb', line 57 def self.sort_alpha self.all.sort_by! {|artist| artist.name} end |
Instance Method Details
#add_issue(issue) ⇒ Object
15 16 17 18 19 |
# File 'lib/star-wars-comics/artist.rb', line 15 def add_issue(issue) artist_var = self.class.to_s.sub("StarWarsComics::Artists::", "").downcase issue.send("#{artist_var}") || issue.send("#{artist_var}=", self) self.issues << issue unless self.issues.include?(issue) end |
#frequent_collaborators ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/star-wars-comics/artist.rb', line 21 def frequent_collaborators collabs_hist = {} self.issues.each do |issue| if collabs_hist.has_key?(issue.writer) collabs_hist[issue.writer] += 1 elsif issue.writer != self collabs_hist[issue.writer] = 0 end if collabs_hist.has_key?(issue.penciller) collabs_hist[issue.penciller] += 1 elsif issue.penciller != self collabs_hist[issue.penciller] = 0 end if collabs_hist.has_key?(issue.letterer) collabs_hist[issue.letterer] += 1 elsif issue.letterer != self collabs_hist[issue.letterer] = 0 end if collabs_hist.has_key?(issue.colorist) collabs_hist[issue.colorist] += 1 elsif issue.colorist != self collabs_hist[issue.colorist] = 0 end end collabs_hist.sort_by {|collab, times| times}.each do |collab, times| puts "#{collab.name}: #{times} times" unless times < 2 end end |