Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command Hash Conversion #55

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
vault_coh (2.0.0)
vault_coh (2.1.0)

GEM
remote: https://rubygems.org/
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Vault

[![Gem Version](https://badge.fury.io/rb/vault_coh.svg)](https://badge.fury.io/rb/vault_coh) [![Documentation](https://img.shields.io/badge/View-Documentation-blue.svg)](https://rubydoc.info/github/ryantaylor/vault-rb/v2.0.0)
[![Gem Version](https://badge.fury.io/rb/vault_coh.svg)](https://badge.fury.io/rb/vault_coh) [![Documentation](https://img.shields.io/badge/View-Documentation-blue.svg)](https://rubydoc.info/github/ryantaylor/vault-rb/v2.1.0)

A native Ruby client wrapper for the [vault](https://github.com/ryantaylor/vault) Company of Heroes replay parser, integrated via a Rust native extension.

Expand All @@ -24,7 +24,7 @@ bytes = File.read('/path/to/replay.rec').unpack('C*')
replay = VaultCoh::Replay.from_bytes(bytes)
puts replay.version
```
All information available from parsing can be found in the [documentation](https://rubydoc.info/github/ryantaylor/vault-rb/v2.0.0).
All information available from parsing can be found in the [documentation](https://rubydoc.info/github/ryantaylor/vault-rb/v2.1.0).

## Contributing

Expand Down
8 changes: 7 additions & 1 deletion ext/vault_coh/src/hash.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use magnus::Value;
use vault::commands::{BuildSquad, SelectBattlegroup, Unknown};
use vault::{Map, Message, Player, Replay};
use vault::{Command, Map, Message, Player, Replay};

pub trait HashExt {
fn to_h(&self) -> Value;
Expand Down Expand Up @@ -30,6 +30,12 @@ impl HashExt for Message {
}
}

impl HashExt for Command {
fn to_h(&self) -> Value {
serde_magnus::serialize(self).unwrap()
}
}

impl HashExt for BuildSquad {
fn to_h(&self) -> Value {
serde_magnus::serialize(self).unwrap()
Expand Down
1 change: 1 addition & 0 deletions ext/vault_coh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ fn init() -> Result<(), Error> {
team.define_method("value", method!(Team::value, 0))?;

let command = module.define_class("Command", class::object())?;
command.define_method("to_h", method!(Command::to_h, 0))?;

let commands_module = module.define_module("Commands")?;

Expand Down
5 changes: 5 additions & 0 deletions lib/vault_coh/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ class Command
#
# @return [Commands::BuildSquad|Commands::SelectBattlegroup|Commands::Unknown]
def value; end

# Returns a hash representation of the object.
#
# @return [Hash]
def to_h; end
end
end
2 changes: 1 addition & 1 deletion lib/vault_coh/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module VaultCoh
VERSION = '2.0.0'
VERSION = '2.1.0'
end
Loading