Class: QuietQuality::Messages

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/quiet_quality/messages.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(messages) ⇒ Messages

Returns a new instance of Messages.



18
19
20
# File 'lib/quiet_quality/messages.rb', line 18

def initialize(messages)
  @messages = messages
end

Class Method Details

.load_data(data) ⇒ Object



5
6
7
8
# File 'lib/quiet_quality/messages.rb', line 5

def self.load_data(data)
  messages = data.map { |message_data| Message.new(**message_data) }
  new(messages)
end

.load_json(text) ⇒ Object



10
11
12
# File 'lib/quiet_quality/messages.rb', line 10

def self.load_json(text)
  load_data(JSON.parse(text))
end

.load_yaml(text) ⇒ Object



14
15
16
# File 'lib/quiet_quality/messages.rb', line 14

def self.load_yaml(text)
  load_data(YAML.safe_load(text))
end

Instance Method Details

#allObject



34
35
36
# File 'lib/quiet_quality/messages.rb', line 34

def all
  messages
end

#each(&block) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/quiet_quality/messages.rb', line 42

def each(&block)
  if block
    messages.each(&block)
  else
    to_enum(:each)
  end
end

#empty?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/quiet_quality/messages.rb', line 38

def empty?
  messages.length == 0
end

#to_hashesObject



22
23
24
# File 'lib/quiet_quality/messages.rb', line 22

def to_hashes
  messages.map(&:to_h)
end

#to_json(pretty: false) ⇒ Object



26
27
28
# File 'lib/quiet_quality/messages.rb', line 26

def to_json(pretty: false)
  pretty ? JSON.pretty_generate(to_hashes) : JSON.generate(to_hashes)
end

#to_yamlObject



30
31
32
# File 'lib/quiet_quality/messages.rb', line 30

def to_yaml
  to_hashes.to_yaml
end