Class: OpenSRF::ClassAndData
- Inherits:
-
Object
- Object
- OpenSRF::ClassAndData
- Defined in:
- lib/opensrf/class_and_data.rb
Overview
OpenSRF requests and responses often take the following form “clasname”, “__p”: [“all”, “the”, “data”]
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(klass:, data:) ⇒ ClassAndData
constructor
A new instance of ClassAndData.
- #to_h ⇒ Object
Constructor Details
#initialize(klass:, data:) ⇒ ClassAndData
Returns a new instance of ClassAndData.
10 11 12 13 |
# File 'lib/opensrf/class_and_data.rb', line 10 def initialize(klass:, data:) @klass = klass @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/opensrf/class_and_data.rb', line 8 def data @data end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
8 9 10 |
# File 'lib/opensrf/class_and_data.rb', line 8 def klass @klass end |
Class Method Details
.parse(hash, path = []) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/opensrf/class_and_data.rb', line 15 def self.parse(hash, path = []) small_json = new(klass: hash['__c'], data: hash['__p']) return small_json if path.empty? key = path.shift parse(small_json.data[key], path) end |
Instance Method Details
#to_h ⇒ Object
23 24 25 26 |
# File 'lib/opensrf/class_and_data.rb', line 23 def to_h { '__c' => @klass, '__p' => @data } end |