Class: Pinnacle::Card
- Inherits:
-
Object
- Object
- Pinnacle::Card
- Defined in:
- lib/rcs/types/card.rb
Constant Summary collapse
- OMIT =
Object.new
Instance Attribute Summary collapse
-
#additional_properties ⇒ OpenStruct
readonly
Additional properties unmapped to the current class definition.
-
#buttons ⇒ Array<Pinnacle::Action>
readonly
Array of buttons attached to the card.
-
#card_style ⇒ Pinnacle::CardStyle
readonly
The style of the card.
-
#image_url ⇒ String
readonly
The URL of the image to be displayed on the card.
-
#subtitle ⇒ String
readonly
The subtitle of the card.
-
#title ⇒ String
readonly
The title of the card.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ Pinnacle::Card
Deserialize a JSON object to an instance of Card.
-
.validate_raw(obj:) ⇒ Void
Leveraged for Union-type generation, validate_raw attempts to parse the given hash and check each fields type against the current object’s property definitions.
Instance Method Summary collapse
- #initialize(title:, subtitle: OMIT, image_url: OMIT, buttons: OMIT, card_style: OMIT, additional_properties: nil) ⇒ Pinnacle::Card constructor
-
#to_json(*_args) ⇒ String
Serialize an instance of Card to a JSON object.
Constructor Details
#initialize(title:, subtitle: OMIT, image_url: OMIT, buttons: OMIT, card_style: OMIT, additional_properties: nil) ⇒ Pinnacle::Card
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rcs/types/card.rb', line 35 def initialize(title:, subtitle: OMIT, image_url: OMIT, buttons: OMIT, card_style: OMIT, additional_properties: nil) @title = title @subtitle = subtitle if subtitle != OMIT @image_url = image_url if image_url != OMIT @buttons = if != OMIT @card_style = card_style if card_style != OMIT @additional_properties = additional_properties @_field_set = { "title": title, "subtitle": subtitle, "image_url": image_url, "buttons": , "card_style": card_style }.reject do |_k, v| v == OMIT end end |
Instance Attribute Details
#additional_properties ⇒ OpenStruct (readonly)
Returns Additional properties unmapped to the current class definition.
21 22 23 |
# File 'lib/rcs/types/card.rb', line 21 def additional_properties @additional_properties end |
#buttons ⇒ Array<Pinnacle::Action> (readonly)
Returns Array of buttons attached to the card. Maximum of 4 buttons.
17 18 19 |
# File 'lib/rcs/types/card.rb', line 17 def @buttons end |
#card_style ⇒ Pinnacle::CardStyle (readonly)
Returns The style of the card.
19 20 21 |
# File 'lib/rcs/types/card.rb', line 19 def card_style @card_style end |
#image_url ⇒ String (readonly)
Returns The URL of the image to be displayed on the card.
15 16 17 |
# File 'lib/rcs/types/card.rb', line 15 def image_url @image_url end |
#subtitle ⇒ String (readonly)
Returns The subtitle of the card.
13 14 15 |
# File 'lib/rcs/types/card.rb', line 13 def subtitle @subtitle end |
#title ⇒ String (readonly)
Returns The title of the card.
11 12 13 |
# File 'lib/rcs/types/card.rb', line 11 def title @title end |
Class Method Details
.from_json(json_object:) ⇒ Pinnacle::Card
Deserialize a JSON object to an instance of Card
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 |
# File 'lib/rcs/types/card.rb', line 57 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) parsed_json = JSON.parse(json_object) title = parsed_json["title"] subtitle = parsed_json["subtitle"] image_url = parsed_json["image_url"] = parsed_json["buttons"]&.map do |item| item = item.to_json Pinnacle::Action.from_json(json_object: item) end if parsed_json["card_style"].nil? card_style = nil else card_style = parsed_json["card_style"].to_json card_style = Pinnacle::CardStyle.from_json(json_object: card_style) end new( title: title, subtitle: subtitle, image_url: image_url, buttons: , card_style: card_style, additional_properties: struct ) end |
.validate_raw(obj:) ⇒ Void
Leveraged for Union-type generation, validate_raw attempts to parse the given
hash and check each fields type against the current object's property
definitions.
96 97 98 99 100 101 102 |
# File 'lib/rcs/types/card.rb', line 96 def self.validate_raw(obj:) obj.title.is_a?(String) != false || raise("Passed value for field obj.title is not the expected type, validation failed.") obj.subtitle&.is_a?(String) != false || raise("Passed value for field obj.subtitle is not the expected type, validation failed.") obj.image_url&.is_a?(String) != false || raise("Passed value for field obj.image_url is not the expected type, validation failed.") obj.&.is_a?(Array) != false || raise("Passed value for field obj.buttons is not the expected type, validation failed.") obj.card_style.nil? || Pinnacle::CardStyle.validate_raw(obj: obj.card_style) end |
Instance Method Details
#to_json(*_args) ⇒ String
Serialize an instance of Card to a JSON object
86 87 88 |
# File 'lib/rcs/types/card.rb', line 86 def to_json(*_args) @_field_set&.to_json end |