Class: QuietQuality::Messages
- Inherits:
-
Object
- Object
- QuietQuality::Messages
- Includes:
- Enumerable
- Defined in:
- lib/quiet_quality/messages.rb
Class Method Summary collapse
Instance Method Summary collapse
- #all ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(messages) ⇒ Messages
constructor
A new instance of Messages.
- #to_hashes ⇒ Object
- #to_json(pretty: false) ⇒ Object
- #to_yaml ⇒ Object
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 = 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) = data.map { || Message.new(**) } new() 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
#all ⇒ Object
34 35 36 |
# File 'lib/quiet_quality/messages.rb', line 34 def all end |
#each(&block) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/quiet_quality/messages.rb', line 42 def each(&block) if block .each(&block) else to_enum(:each) end end |
#empty? ⇒ Boolean
38 39 40 |
# File 'lib/quiet_quality/messages.rb', line 38 def empty? .length == 0 end |
#to_hashes ⇒ Object
22 23 24 |
# File 'lib/quiet_quality/messages.rb', line 22 def to_hashes .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_yaml ⇒ Object
30 31 32 |
# File 'lib/quiet_quality/messages.rb', line 30 def to_yaml to_hashes.to_yaml end |