Class: ActionMCP::Client::Catalog::Resource
- Inherits:
-
Object
- Object
- ActionMCP::Client::Catalog::Resource
- Defined in:
- lib/action_mcp/client/catalog.rb
Overview
Internal Resource class to represent individual resources
Instance Attribute Summary collapse
-
#annotations ⇒ Object
readonly
Returns the value of attribute annotations.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#mime_type ⇒ Object
readonly
Returns the value of attribute mime_type.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#extension ⇒ String?
Get the file extension from the resource name.
-
#image? ⇒ Boolean
Check if this resource is an image based on MIME type.
-
#initialize(data = []) ⇒ Resource
constructor
Initialize a new Resource instance.
-
#path ⇒ String?
Get the path portion of the URI.
-
#text? ⇒ Boolean
Check if this resource is a text file based on MIME type.
-
#to_h ⇒ Hash
Generate a hash representation of the resource.
Constructor Details
#initialize(data = []) ⇒ Resource
Initialize a new Resource instance
111 112 113 114 115 116 117 |
# File 'lib/action_mcp/client/catalog.rb', line 111 def initialize(data = []) @uri = data["uri"] @name = data["name"] @description = data["description"] @mime_type = data["mimeType"] @annotations = data["annotations"] || {} end |
Instance Attribute Details
#annotations ⇒ Object (readonly)
Returns the value of attribute annotations.
106 107 108 |
# File 'lib/action_mcp/client/catalog.rb', line 106 def annotations @annotations end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
106 107 108 |
# File 'lib/action_mcp/client/catalog.rb', line 106 def description @description end |
#mime_type ⇒ Object (readonly)
Returns the value of attribute mime_type.
106 107 108 |
# File 'lib/action_mcp/client/catalog.rb', line 106 def mime_type @mime_type end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
106 107 108 |
# File 'lib/action_mcp/client/catalog.rb', line 106 def name @name end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
106 107 108 |
# File 'lib/action_mcp/client/catalog.rb', line 106 def uri @uri end |
Instance Method Details
#extension ⇒ String?
Get the file extension from the resource name
122 123 124 |
# File 'lib/action_mcp/client/catalog.rb', line 122 def extension File.extname(@name)[1..] if @name.include?(".") end |
#image? ⇒ Boolean
Check if this resource is an image based on MIME type
136 137 138 |
# File 'lib/action_mcp/client/catalog.rb', line 136 def image? @mime_type&.start_with?("image/") end |
#path ⇒ String?
Get the path portion of the URI
143 144 145 146 147 |
# File 'lib/action_mcp/client/catalog.rb', line 143 def path URI(@uri).path rescue StandardError nil end |
#text? ⇒ Boolean
Check if this resource is a text file based on MIME type
129 130 131 |
# File 'lib/action_mcp/client/catalog.rb', line 129 def text? @mime_type&.start_with?("text/") end |
#to_h ⇒ Hash
Generate a hash representation of the resource
152 153 154 155 156 157 158 159 160 |
# File 'lib/action_mcp/client/catalog.rb', line 152 def to_h { "uri" => @uri, "name" => @name, "description" => @description, "mimeType" => @mime_type, "annotations" => @annotations } end |