class Squad::Team
Attributes
associates[RW]
location[RW]
members[RW]
Public Class Methods
new(parsed_data, people)
click to toggle source
# File lib/terraorg/model/squad.rb, line 26 def initialize(parsed_data, people) location = parsed_data.fetch('location') country = ISO3166::Country.new(location) raise "Location is invalid: #{location}" unless country @location = country.alpha2 @members = parsed_data.fetch('members', []).map do |n| people.get_or_create!(n) end @associates = parsed_data.fetch('associates', []).map do |n| people.get_or_create!(n) end end
Public Instance Methods
everyone()
click to toggle source
# File lib/terraorg/model/squad.rb, line 61 def everyone @associates + @members end
to_h()
click to toggle source
Output a canonical (sorted, formatted) version of this Team
.
-
Sort the members in each team
-
Only add an associates field if it's present
# File lib/terraorg/model/squad.rb, line 53 def to_h { 'associates' => @associates.map(&:id).sort, 'location' => @location, 'members' => @members.map(&:id).sort, } end
to_md()
click to toggle source
# File lib/terraorg/model/squad.rb, line 65 def to_md "**#{@location}**: #{@members.map(&:name).sort.join(', ')}, #{@associates.map { |m| "_#{m.name}_" }.sort.join(', ')}" end
validate!()
click to toggle source
# File lib/terraorg/model/squad.rb, line 39 def validate! raise 'Subteam has no full time members' if @members.size == 0 # location validation done at initialize time # associates can be empty # associates and members must have zero intersection associate_set = Set.new(@associates.map(&:id)) member_set = Set.new(@members.map(&:id)) raise 'A member cannot also be an associate of the same team' if associate_set.intersection(member_set) end