Class: Licensed::Report

Inherits:
Hash
  • Object
show all
Defined in:
lib/licensed/report.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, target:) ⇒ Report

Returns a new instance of Report.



7
8
9
10
11
# File 'lib/licensed/report.rb', line 7

def initialize(name:, target:)
  super()
  @name = name
  @target = target
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/licensed/report.rb', line 5

def name
  @name
end

#targetObject (readonly)

Returns the value of attribute target.



6
7
8
# File 'lib/licensed/report.rb', line 6

def target
  @target
end

Instance Method Details

#all_reportsObject



25
26
27
28
29
# File 'lib/licensed/report.rb', line 25

def all_reports
  result = []
  result << self
  result.push(*reports.flat_map(&:all_reports))
end

#errorsObject



17
18
19
# File 'lib/licensed/report.rb', line 17

def errors
  @errors ||= []
end

#reportsObject



13
14
15
# File 'lib/licensed/report.rb', line 13

def reports
  @reports ||= []
end

#to_hObject

Returns the data from the report as a hash



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/licensed/report.rb', line 32

def to_h
  # add name, errors and warnings if they have real data
  output = {}
  output["name"] = name unless name.to_s.empty?
  output["errors"] = errors.dup if errors.any?
  output["warnings"] = warnings.dup if warnings.any?

  # merge the hash data from the report.  command-specified data always
  # overwrites local data
  output.merge(super)
end

#warningsObject



21
22
23
# File 'lib/licensed/report.rb', line 21

def warnings
  @warnings ||= []
end