Class: StarWarsComics::Artist

Inherits:
Object
  • Object
show all
Extended by:
Concerns::Findable
Defined in:
lib/star-wars-comics/artist.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#issuesObject

Returns the value of attribute issues.



4
5
6
# File 'lib/star-wars-comics/artist.rb', line 4

def issues
  @issues
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/star-wars-comics/artist.rb', line 4

def name
  @name
end

#pathObject

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

.allObject



61
62
63
# File 'lib/star-wars-comics/artist.rb', line 61

def self.all
  @@all
end

.sort_alphaObject



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_collaboratorsObject



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