-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from starkbank/add/invoice-rules
Add/invoice rules
- Loading branch information
Showing
7 changed files
with
68 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require_relative('../utils/rest') | ||
|
||
module StarkBank | ||
class Invoice | ||
# # Invoice::Rule object | ||
# | ||
# The Invoice::Rule object modifies the behavior of Invoice objects when passed as an argument upon their creation. | ||
# | ||
# ## Parameters (required): | ||
# - key [string]: Rule to be customized, describes what Invoice behavior will be altered. ex: "allowedTaxIds" | ||
# - value [list of string]: Value of the rule. ex: ['012.345.678-90', '45.059.493/0001-73'] | ||
class Rule < StarkCore::Utils::SubResource | ||
attr_reader :key, :value | ||
def initialize(key:, value:) | ||
@key = key | ||
@value = value | ||
end | ||
|
||
def self.parse_rules(rules) | ||
resource_maker = StarkBank::Invoice::Rule.resource[:resource_maker] | ||
return rules if rules.nil? | ||
|
||
parsed_rules = [] | ||
rules.each do |rule| | ||
unless rule.is_a? Rule | ||
rule = StarkCore::Utils::API.from_api_json(resource_maker, rule) | ||
end | ||
parsed_rules << rule | ||
end | ||
return parsed_rules | ||
end | ||
|
||
def self.resource | ||
{ | ||
resource_name: 'Rule', | ||
resource_maker: proc { |json| | ||
Rule.new( | ||
key: json['key'], | ||
value: json['value'] | ||
) | ||
} | ||
} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters