Class: EveOnline::Api::SkillGroups

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/eve_online/api/skill_groups.rb

Instance Method Summary collapse

Constructor Details

#initialize(fragment) ⇒ SkillGroups

Returns a new instance of SkillGroups.



7
8
9
# File 'lib/eve_online/api/skill_groups.rb', line 7

def initialize fragment
  self.fragment = fragment
end

Instance Method Details

#eachObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/eve_online/api/skill_groups.rb', line 11

def each
  rows = fragment.xpath './row'
  skill_groups = rows.map do |row|
    skill_group = SkillGroup.new row
  end
  skill_groups.group_by { |sg| sg.id }.each do |id, groups|
    group = groups.pop
    while next_group = groups.pop
      group.merge next_group
    end
    yield group
  end
end

#to_s(indent = 0) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/eve_online/api/skill_groups.rb', line 26

def to_s indent = 0
  margin = " " * indent
  ["#{margin}Skill Groups (#{to_a.size})"].tap do |s|
    sort.each do |skill_group|
      s << skill_group.to_s(indent + 2)
    end
  end.join "\n"        
end