Class: StorageFormat
- Inherits:
-
Object
- Object
- StorageFormat
- Defined in:
- lib/storage_format.rb
Constant Summary collapse
- VALID_OPTIONS =
[:type, :title, :spacekey, :content, :pageid, :parentid, :version]
Instance Attribute Summary collapse
-
#page_format ⇒ Object
Returns the value of attribute page_format.
Instance Method Summary collapse
- #get_type_of_storage(type) ⇒ Object
-
#initialize(**options) ⇒ StorageFormat
constructor
A new instance of StorageFormat.
Constructor Details
#initialize(**options) ⇒ StorageFormat
Returns a new instance of StorageFormat.
6 7 8 9 10 11 12 13 14 |
# File 'lib/storage_format.rb', line 6 def initialize(**) .each do |key, value| # puts "--> #{key} = #{value}" raise "\n*** Error: unknown option #{key.inspect}\nValid option are:\n#{VALID_OPTIONS}" unless (VALID_OPTIONS.include?(key)) instance_variable_set("@#{key}", value) end @page_format = get_type_of_storage(@type) end |
Instance Attribute Details
#page_format ⇒ Object
Returns the value of attribute page_format.
2 3 4 |
# File 'lib/storage_format.rb', line 2 def page_format @page_format end |
Instance Method Details
#get_type_of_storage(type) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/storage_format.rb', line 16 def get_type_of_storage(type) case type when 'create_page_with_no_parent' if [@title, @spacekey, @content].include?(nil) puts "*** ERROR: Undefined parameter(s)\n Inspection: #{self.inspect}" exit(false) else %Q( { "type": "page", "title": "#{@title}", "space": { "key": "#{@spacekey}" }, "body": { "storage": { "value": "#{@content}", "representation": "storage" } } } ) end when 'create_page_with_parent' if [@parentid, @title, @spacekey, @content].include?(nil) puts "*** ERROR: Undefined parameter(s)\n Inspection: #{self.inspect}" exit(false) else %Q( { "type": "page", "ancestors": [{"type":"page","id":"#{@parentid}"}], "title": "#{@title}", "space": { "key": "#{@spacekey}" }, "body": { "storage": { "value": "#{@content}", "representation": "storage" } } } ) end when 'update_page_with_no_parent' if [@pageid, @title, @spacekey, @content, @version].include?(nil) puts "*** ERROR: Undefined parameter(s)\n Inspection: #{self.inspect}" exit(false) else %Q( { "id":"#{@pageid}", "type":"page", "title":"#{@title}", "space": { "key":"#{@spacekey}" }, "body": { "storage": { "value":"#{@content}", "representation":"storage" } }, "version": { "number":"#{@version}" } } ) end when 'update_page_with_parent' if [@pageid, @parentid, @title, @spacekey, @content, @version].include?(nil) puts "*** ERROR: Undefined parameter(s)\n Inspection: #{self.inspect}" exit(false) else %Q( { "id":"#{@pageid}", "type":"page", "ancestors": [{"type":"page","id":"#{@parentid}"}], "title":"#{@title}", "space": { "key":"#{@spacekey}" }, "body": { "storage": { "value":"#{@content}", "representation":"storage" } }, "version": { "number":"#{@version}" } } ) end else puts "***ERROR: Wrong parameters for #{self.class.name}" exit(false) end end |