Skip to content

Commit

Permalink
#51 pmp
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Aug 2, 2024
1 parent 6a88af4 commit 343f364
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ Layout/EndOfLine:
EnforcedStyle: lf
Security/MarshalLoad:
Enabled: false
Metrics/ParameterLists:
Enabled: false
Layout/MultilineAssignmentLayout:
Enabled: true
11 changes: 10 additions & 1 deletion lib/fbe/award.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,17 @@
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
# License:: MIT
class Fbe::Award
def initialize(query = J.pmp.hr.send($judge.gsub('-', '_')))
# Ctor.
# @param [String] query The query with the policy
# @param [String] judge The name of the judge
def initialize(query = nil, judge: $judge, fb: Fbe.fb, global: $global, options: $options, loog: $loog)
@query = Fbe.pmp(fb:, global:, options:, loog:).hr.send(judge.gsub('-', '_')) if query.nil?
@query = query
end

# Build a bill object from this award query.
# @param [Hash] vars Hash of variables
# @return [Fbe::Award::Bill] The bill
def bill(vars = {})
term = Factbase::Syntax.new(@query, term: Fbe::Award::BTerm).to_term
bill = Bill.new
Expand All @@ -59,6 +66,8 @@ def bill(vars = {})
bill
end

# Build a policy object from this award query.
# @return [Fbe::Award::Policy] The policy
def policy
term = Factbase::Syntax.new(@query, term: Fbe::Award::PTerm).to_term
policy = Policy.new
Expand Down
43 changes: 43 additions & 0 deletions lib/fbe/pmp.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

# MIT License
#
# Copyright (c) 2024 Zerocracy
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

require 'others'
require_relative 'fb'

# Project management functions.
module Fbe; end

def Fbe.pmp(fb: Fbe.fb, global: $global, options: $options, loog: $loog)
others do |*args1|
area = args1.first
others do |*args2|
param = args2.first
f = Fbe.fb(global:, fb:, options:, loog:).query("(and (eq what 'pmp') (eq area '#{area}'))").each.to_a.first
raise "Unknown area '#{area}'" if f.nil?
r = f[param]
raise "Unknown property '#{param}' in the '#{area}' area" if r.nil?
r.first
end
end
end
54 changes: 54 additions & 0 deletions test/fbe/test_pmp.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# frozen_string_literal: true

# MIT License
#
# Copyright (c) 2024 Zerocracy
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

require 'minitest/autorun'
require 'judges/options'
require 'loog'
require 'factbase'
require_relative '../test__helper'
require_relative '../../lib/fbe/pmp'

# Test.
# Author:: Yegor Bugayenko (yegor256@gmail.com)
# Copyright:: Copyright (c) 2024 Zerocracy
# License:: MIT
class TestPmp < Minitest::Test
def test_defaults
$fb = Factbase.new
$global = {}
$options = Judges::Options.new
f = Fbe.fb(loog: Loog::NULL).insert
f.what = 'pmp'
f.area = 'hr'
f.days_to_reward = 55
$loog = Loog::NULL
assert_equal(55, Fbe.pmp(loog: Loog::NULL).hr.days_to_reward)
end

def test_fail_on_wrong_area
$global = {}
$loog = Loog::NULL
assert_raises { Fbe.pmp(Factbase.new, loog: Loog::NULL).something }
end
end

0 comments on commit 343f364

Please sign in to comment.