Class: Sashite::Pcn::Game::Meta
- Inherits:
-
Object
- Object
- Sashite::Pcn::Game::Meta
- Defined in:
- lib/sashite/pcn/game/meta.rb
Overview
Represents game metadata with standard and custom fields
All fields are optional. An empty Meta object (no metadata) is valid. Standard fields are validated, custom fields are accepted without validation.
Constant Summary collapse
- ERROR_INVALID_NAME =
Error messages
"name must be a string"- ERROR_INVALID_EVENT =
"event must be a string"- ERROR_INVALID_LOCATION =
"location must be a string"- ERROR_INVALID_ROUND =
"round must be a positive integer (>= 1)"- ERROR_INVALID_STARTED_AT =
"started_at must be in ISO 8601 datetime format (e.g., 2025-01-27T14:00:00Z)"- ERROR_INVALID_HREF =
"href must be an absolute URL (http:// or https://)"- STANDARD_FIELDS =
Standard field keys
i[name event location round started_at href].freeze
- DATETIME_PATTERN =
Regular expressions for validation ISO 8601 datetime - accepts various formats:
-
Basic: 2025-01-27T14:00:00Z
-
With milliseconds: 2025-01-27T14:00:00.123Z
-
With timezone offset: 2025-01-27T14:00:00+02:00
-
Local time without timezone: 2025-01-27T14:00:00
-
/\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?\z/- URL_PATTERN =
/\Ahttps?:\/\/.+/
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Check equality with another Meta object.
-
#[](key) ⇒ Object?
Get a metadata value by key.
-
#each {|key, value| ... } ⇒ Enumerator
Iterate over each metadata field.
-
#empty? ⇒ Boolean
Check if no metadata is present.
-
#hash ⇒ Integer
Hash code for use in collections.
-
#initialize(**fields) ⇒ Meta
constructor
Create a new Meta instance.
-
#inspect ⇒ String
String representation for debugging.
-
#key?(key) ⇒ Boolean
Check if a metadata field is present.
-
#keys ⇒ Array<Symbol>
Get all metadata keys.
-
#to_h ⇒ Hash
Convert to hash representation.
Constructor Details
#initialize(**fields) ⇒ Meta
Create a new Meta instance
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/sashite/pcn/game/meta.rb', line 57 def initialize(**fields) @data = {} # Process and validate each field fields.each do |key, value| validate_and_store(key, value) end @data.freeze freeze end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Check equality with another Meta object
153 154 155 156 157 |
# File 'lib/sashite/pcn/game/meta.rb', line 153 def ==(other) return false unless other.is_a?(self.class) @data == other.to_h end |
#[](key) ⇒ Object?
Get a metadata value by key
77 78 79 |
# File 'lib/sashite/pcn/game/meta.rb', line 77 def [](key) @data[key.to_sym] end |
#each {|key, value| ... } ⇒ Enumerator
Iterate over each metadata field
120 121 122 123 124 |
# File 'lib/sashite/pcn/game/meta.rb', line 120 def each(&) return @data.each unless block_given? @data.each(&) end |
#empty? ⇒ Boolean
Check if no metadata is present
87 88 89 |
# File 'lib/sashite/pcn/game/meta.rb', line 87 def empty? @data.empty? end |
#hash ⇒ Integer
Hash code for use in collections
164 165 166 |
# File 'lib/sashite/pcn/game/meta.rb', line 164 def hash @data.hash end |
#inspect ⇒ String
String representation for debugging
145 146 147 |
# File 'lib/sashite/pcn/game/meta.rb', line 145 def inspect "#<#{self.class.name} #{@data.inspect}>" end |
#key?(key) ⇒ Boolean
Check if a metadata field is present
109 110 111 |
# File 'lib/sashite/pcn/game/meta.rb', line 109 def key?(key) @data.key?(key.to_sym) end |
#keys ⇒ Array<Symbol>
Get all metadata keys
97 98 99 |
# File 'lib/sashite/pcn/game/meta.rb', line 97 def keys @data.keys end |
#to_h ⇒ Hash
Convert to hash representation
138 139 140 |
# File 'lib/sashite/pcn/game/meta.rb', line 138 def to_h @data.dup.freeze end |