Skip to content

Commit

Permalink
feat: create sentiment
Browse files Browse the repository at this point in the history
  • Loading branch information
benzend committed Oct 11, 2024
1 parent 3577bb2 commit cf537c7
Show file tree
Hide file tree
Showing 18 changed files with 259 additions and 96 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions .idea/glare-ux-metrics-rb.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.6.9
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

source "https://rubygems.org"

# Specify your gem's dependencies in glare-ux-metrics-rb.gemspec
# Specify your gem's dependencies in glare-ux-metrics-metrics-rb.gemspec
gemspec

gem "rake", "~> 13.0"

gem "rspec", "~> 3.0"
gem "rspec", "~> 3.1"

gem "rubocop", "~> 1.21"
59 changes: 59 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
PATH
remote: .
specs:
glare-ux-metrics-metrics-rb (0.1.0)

GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
diff-lcs (1.5.0)
json (2.6.3)
parallel (1.23.0)
parser (3.3.0.4)
ast (~> 2.4.1)
racc
racc (1.8.1)
rainbow (3.1.1)
rake (13.2.1)
regexp_parser (2.8.2)
rexml (3.3.7)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.1)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
rubocop (1.50.2)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.2.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
ruby-progressbar (1.13.0)
unicode-display_width (2.5.0)

PLATFORMS
ruby

DEPENDENCIES
glare-ux-metrics-metrics-rb!
rake (~> 13.0)
rspec (~> 3.1)
rubocop (~> 1.21)

BUNDLED WITH
2.4.21
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Glare::Ux::Metrics::Rb
# Glare::UxMetrics

TODO: Delete this and the text below, and describe your gem

Expand Down Expand Up @@ -36,4 +36,4 @@ The gem is available as open source under the terms of the [MIT License](https:/

## Code of Conduct

Everyone interacting in the Glare::Ux::Metrics::Rb project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/glare-ux-metrics-rb/blob/main/CODE_OF_CONDUCT.md).
Everyone interacting in the Glare::UxMetrics project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/glare-ux-metrics-rb/blob/main/CODE_OF_CONDUCT.md).
2 changes: 1 addition & 1 deletion bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# frozen_string_literal: true

require "bundler/setup"
require "glare/ux/metrics/rb"
require "glare/ux-metrics/ux-metrics"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand Down
18 changes: 9 additions & 9 deletions glare-ux-metrics-rb.gemspec
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# frozen_string_literal: true

require_relative "lib/glare/ux/metrics/rb/version"
require_relative "lib/glare/ux-metrics/version"

Gem::Specification.new do |spec|
spec.name = "glare-ux-metrics-rb"
spec.version = Glare::Ux::Metrics::Rb::VERSION
spec.name = "glare-ux-metrics-metrics-rb"
spec.version = Glare::UxMetrics::VERSION
spec.authors = ["Benjamin Scott"]
spec.email = ["[email protected]"]

spec.summary = "TODO: Write a short summary, because RubyGems requires one."
spec.description = "TODO: Write a longer description or delete this line."
spec.homepage = "TODO: Put your gem's website or public repo URL here."
spec.summary = "A UX Metric framework for ruby projects"
spec.description = "A UX Metric framework for ZURB"
spec.homepage = "https://github.com/zurb/glare-ux-metrics-rb"
spec.license = "MIT"
spec.required_ruby_version = ">= 2.6.0"

spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
spec.metadata["allowed_push_host"] = "https://github.com/zurb/glare-ux-metrics-rb"

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
spec.metadata["source_code_uri"] = "https://github.com/zurb/glare-ux-metrics-rb"
spec.metadata["changelog_uri"] = "https://github.com/zurb/glare-ux-metrics-rb/CHANGELOG.md"

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
Expand Down
81 changes: 81 additions & 0 deletions lib/glare/ux-metrics/ux-metrics.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# frozen_string_literal: true

module Glare
module UxMetrics
class Error < StandardError; end

module Sentiment
class Data
CHOICE_KEYS = %w[helpful innovative simple complicated confusing overwhelming annoying].freeze

def initialize(choices:)
@choices = choices
end

attr_reader :choices

def valid?
if choices.is_a?(Hash) && choices.size
missing_attributes = CHOICE_KEYS - choices.keys.map(&:to_s)
return true if missing_attributes.empty?
end

false
end

def parse
result = choices[:helpful].to_f +
choices[:innovative].to_f +
choices[:simple].to_f +
choices[:joyful].to_f -
choices[:complicated].to_f -
choices[:confusing].to_f -
choices[:overwhelming].to_f -
choices[:annoying].to_f

threshold = if result > 1.5
'positive'
elsif result > 1.0
'neutral'
else
'negative'
end

Result.new(result: result, threshold: threshold, label: threshold)
end

class InvalidDataError < Error
def initialize(msg = "Data not valid. Correct data format is: \n\n#{correct_data}")
super(msg)
end

def correct_data
{
choices: {
helpful: "string|integer|float",
innovative: "string|integer|float",
simple: "string|integer|float",
joyful: "string|integer|float",
complicated: "string|integer|float",
confusing: "string|integer|float",
overwhelming: "string|integer|float",
annoying: "string|integer|float",
}
}.to_json
end
end
end

class Result
def initialize(result:, threshold:, label:)
@result = result
@threshold = threshold
@label = label
end

attr_reader :result, :threshold, :label

end
end
end
end
7 changes: 7 additions & 0 deletions lib/glare/ux-metrics/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

module Glare
module UxMetrics
VERSION = "0.1.0"
end
end
59 changes: 0 additions & 59 deletions lib/glare/ux/metrics/rb.rb

This file was deleted.

11 changes: 0 additions & 11 deletions lib/glare/ux/metrics/rb/version.rb

This file was deleted.

32 changes: 32 additions & 0 deletions sig/glare/ux_metrics/ux-metrics.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Glare
module UxMetrics
class Error < StandardError
end
module Sentiment
class Data
CHOICE_KEYS: Array[String]
attr_reader choices: Hash[::String, ::String | ::Float | ::Integer]

def initialize: (choices: Hash[::String, ::String | ::Float | ::Integer]) -> void

def valid?: -> bool

def parse: -> Result

class InvalidDataError < Error
def correct_data: -> String
end
end

class Result
attr_reader result: Float
attr_reader label: String
attr_reader threshold: String

def initialize: (result: Float, label: String, threshold: String) -> void
end
end

VERSION: String
end
end
7 changes: 7 additions & 0 deletions spec/glare/ux-metrics/ux-metrics.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

RSpec.describe Glare::UxMetrics do
it "does something useful" do
expect(false).to eq(true)
end
end
Loading

0 comments on commit cf537c7

Please sign in to comment.