Class: Platoons
- Inherits:
-
Object
- Object
- Platoons
- Defined in:
- lib/terraorg/model/platoons.rb
Constant Summary collapse
- SCHEMA_VERSION =
'v1'.freeze
Instance Method Summary collapse
- #all ⇒ Object
- #all_names ⇒ Object
- #all_squad_names ⇒ Object
-
#initialize(parsed_data, squads, people, gsuite_domain) ⇒ Platoons
constructor
A new instance of Platoons.
- #lookup!(name) ⇒ Object
- #members ⇒ Object
- #to_h ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(parsed_data, squads, people, gsuite_domain) ⇒ Platoons
Returns a new instance of Platoons.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/terraorg/model/platoons.rb', line 20 def initialize(parsed_data, squads, people, gsuite_domain) version = parsed_data.fetch('version') raise "Unsupported schema version: #{version}" if version != SCHEMA_VERSION @platoons = {} parsed_data.fetch('platoons').each do |platoon_raw| p = Platoon.new(platoon_raw, squads, people, gsuite_domain) @platoons[p.id] = p end end |
Instance Method Details
#all ⇒ Object
38 39 40 |
# File 'lib/terraorg/model/platoons.rb', line 38 def all @platoons.values end |
#all_names ⇒ Object
46 47 48 |
# File 'lib/terraorg/model/platoons.rb', line 46 def all_names @platoons.keys end |
#all_squad_names ⇒ Object
42 43 44 |
# File 'lib/terraorg/model/platoons.rb', line 42 def all_squad_names @platoons.values.map(&:squad_names).flatten end |
#lookup!(name) ⇒ Object
31 32 33 |
# File 'lib/terraorg/model/platoons.rb', line 31 def lookup!(name) @platoons.fetch(name) end |
#members ⇒ Object
50 51 52 |
# File 'lib/terraorg/model/platoons.rb', line 50 def members @platoons.map(&:members).flatten end |
#to_h ⇒ Object
54 55 56 |
# File 'lib/terraorg/model/platoons.rb', line 54 def to_h { 'version' => SCHEMA_VERSION , 'platoons' => @platoons.values.sort_by(&:id).map(&:to_h) } end |
#validate! ⇒ Object
35 36 |
# File 'lib/terraorg/model/platoons.rb', line 35 def validate! end |