Class: TechRadar::Radar

Inherits:
Object
  • Object
show all
Defined in:
app/models/tech_radar/radar.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRadar

Returns a new instance of Radar.



4
5
6
# File 'app/models/tech_radar/radar.rb', line 4

def initialize
  @data = YAML.load_file(Rails.root + "config" + "tech-radar.yml")
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'app/models/tech_radar/radar.rb', line 3

def data
  @data
end

Instance Method Details

#quadrant(quadrant_name) ⇒ Object



14
15
16
17
18
19
20
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 'app/models/tech_radar/radar.rb', line 14

def quadrant(quadrant_name)
  quadrant = @data.fetch(quadrant_name)
  by_ring = {}
  quadrant.each do |(ring,technologies)|
    by_ring[ring] ||= []
    (technologies || {}).each do |(name,data)|
      experts = Array(data["experts"]).map { |name_or_hash|
        if name_or_hash.kind_of?(String)
          Expert.new(name: name_or_hash)
        else
          Expert.new(name: name_or_hash.fetch("name"), email: name_or_hash["email"])
        end
      }.sort_by(&:name)

      examples = Array(data["examples"]).map { |url_or_hash|
        if url_or_hash.kind_of?(String)
          Example.new(url: url_or_hash)
        else
          Example.new(url: url_or_hash.fetch("url"), title: url_or_hash["title"])
        end
      }.sort_by { |example| example.title.to_s }

      by_ring[ring] << Technology.new(name: name,
                                      ring: ring,
                                      quadrant: quadrant_name,
                                      purpose: data["purpose"],
                                      more_details_url: data["more_details_url"],
                                      more_details_summary: data["more_details_summary"],
                                      why_url: data["why_url"],
                                      tags: Array(data["tags"]).sort,
                                      experts: experts,
                                      examples: examples,
                                      why_summary: data["why_summary"])
    end
  end
  TechRadar::Quadrant.new(
    name: quadrant_name, 
    rings: by_ring.map { |ring_name,technologies| 
      TechRadar::Ring.new(name: ring_name, technologies: technologies.sort_by { |tech| tech.name.downcase }) 
    }
  )
end

#quadrantsObject



8
9
10
11
12
# File 'app/models/tech_radar/radar.rb', line 8

def quadrants
  @data.keys.map { |quadrant_name|
    quadrant(quadrant_name)
  }
end

#ring(ring_name) ⇒ Object



63
64
65
# File 'app/models/tech_radar/radar.rb', line 63

def ring(ring_name)
  rings.detect { |ring| ring.name == ring_name }
end

#ringsObject



57
58
59
60
61
# File 'app/models/tech_radar/radar.rb', line 57

def rings
  quadrants.map(&:rings).flatten.group_by(&:name).map { |(ring_name,rings)|
    TechRadar::Ring.new(name: ring_name,technologies: rings.map(&:technologies).flatten.sort_by { |tech| tech.name.downcase })
  }
end

#technologies(options = {}) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/models/tech_radar/radar.rb', line 67

def technologies(options = {})
  results = quadrants.
    map(&:rings).
    flatten.
    map(&:technologies).
    flatten

  if options[:tagged]
    results = results.select { |technology|
      technology.tags.include?(options[:tagged])
    }
  end
  results.sort_by { |technology| technology.name.downcase }
end

#technology(name) ⇒ Object



82
83
84
# File 'app/models/tech_radar/radar.rb', line 82

def technology(name)
  technologies.detect { |technology| technology.name == name }
end