inci_score 4.2.1 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,6 +5,7 @@ require 'yaml'
5
5
  module InciScore
6
6
  module Config
7
7
  CATALOG = YAML::load_file(File::expand_path('../../../config/catalog.yml', __FILE__)).freeze
8
+ CIR = File.readlines(File::expand_path('../../../config/cir', __FILE__)).freeze
8
9
  HAZARDS = YAML::load_file(File::expand_path('../../../config/hazards.yml', __FILE__)).freeze
9
10
  end
10
11
  end
@@ -5,14 +5,13 @@ module InciScore
5
5
  SLASH = '/'
6
6
  SLASH_RULE = /(?<!ate)\//.freeze
7
7
  PARENTHESIS = %w[( ) [ ]].freeze
8
- DETAILS_RULE = /(\(.+\)|\[.+\])/.freeze
8
+ PARENTHESIS_RULE = /(\(.+\)|\[.+\])/.freeze
9
9
 
10
- attr_reader :raw, :tokens, :values
10
+ attr_reader :raw, :values
11
11
 
12
12
  def initialize(raw)
13
13
  @raw = raw.to_s
14
- @tokens = @raw.split(SLASH_RULE).map(&:strip)
15
- @values ||= synonims.unshift(name).compact
14
+ @values = fetch_values
16
15
  freeze
17
16
  end
18
17
 
@@ -22,13 +21,15 @@ module InciScore
22
21
 
23
22
  private
24
23
 
25
- def name
26
- return tokens.first unless parenthesis?
27
- raw.sub(DETAILS_RULE, '').strip
28
- end
29
-
30
- def synonims
31
- tokens[1, tokens.size].to_a
24
+ def fetch_values
25
+ if parenthesis?
26
+ parenthesis = PARENTHESIS.join
27
+ parenthesis_values = raw.match(PARENTHESIS_RULE).captures.map { |c| c.delete(parenthesis) }
28
+ deparenthesized = raw.sub(PARENTHESIS_RULE, '').sub(/\s+/, ' ').strip
29
+ [deparenthesized].concat(parenthesis_values)
30
+ else
31
+ raw.split(SLASH_RULE).map(&:strip)
32
+ end
32
33
  end
33
34
 
34
35
  def parenthesis?
@@ -8,8 +8,8 @@ module InciScore
8
8
 
9
9
  attr_reader :ingredient, :rules, :applied
10
10
 
11
- def initialize(ingredient, rules = DEFAULT_RULES, wrapper = Ingredient)
12
- @ingredient = wrapper.new(ingredient)
11
+ def initialize(ingredient, rules = DEFAULT_RULES)
12
+ @ingredient = Ingredient.new(ingredient)
13
13
  @rules = rules
14
14
  @applied = []
15
15
  freeze
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InciScore
4
- VERSION = '4.2.1'
4
+ VERSION = '4.3.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inci_score
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.1
4
+ version: 4.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - costajob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-04 00:00:00.000000000 Z
11
+ date: 2023-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -106,6 +106,7 @@ files:
106
106
  - README.md
107
107
  - bin/inci_score
108
108
  - config/catalog.yml
109
+ - config/cir
109
110
  - config/hazards.yml
110
111
  - ext/levenshtein.c
111
112
  - lib/inci_score.rb