Class: DuperVisor::Content

Inherits:
Object
  • Object
show all
Defined in:
lib/dupervisor/content.rb

Overview

This class is responsible for taking the input and converting it into a Hash. It can also be initialized with the Hash, in which no conversion is performed.

The result

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body: nil, format: nil) ⇒ Content

Returns a new instance of Content.



14
15
16
17
18
# File 'lib/dupervisor/content.rb', line 14

def initialize(body: nil, format: nil)
  self.body   = body
  self.format = format
  self.parse_result = {}
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



12
13
14
# File 'lib/dupervisor/content.rb', line 12

def body
  @body
end

#formatObject

Returns the value of attribute format.



12
13
14
# File 'lib/dupervisor/content.rb', line 12

def format
  @format
end

#parse_resultObject

Returns the value of attribute parse_result.



12
13
14
# File 'lib/dupervisor/content.rb', line 12

def parse_result
  @parse_result
end

Class Method Details

.to_format_from(hash, format) ⇒ Object

Raises:

  • (ArgumentError)


20
21
22
23
24
# File 'lib/dupervisor/content.rb', line 20

def self.to_format_from(hash, format)
  format_class = ::DuperVisor::Formats::Base.formats[format]
  raise ArgumentError.new("No format #{format} found") unless format_class
  Content.new(body: format_class.to.call(hash), format: format_class.format)
end