class InciScore::Ingredient
Constants
- DETAILS_RULE
- PARENTHESIS
- SLASH
- SLASH_RULE
Public Class Methods
new(raw)
click to toggle source
# File lib/inci_score/ingredient.rb, line 8 def initialize(raw) @raw = raw.to_s @tokens = @raw.split(SLASH_RULE).map(&:strip) end
Public Instance Methods
to_s()
click to toggle source
# File lib/inci_score/ingredient.rb, line 13 def to_s values.join(SLASH) end
values()
click to toggle source
# File lib/inci_score/ingredient.rb, line 17 def values @values ||= synonims.unshift(name).compact end
Private Instance Methods
details()
click to toggle source
# File lib/inci_score/ingredient.rb, line 30 def details return unless parenthesis? @raw.match(DETAILS_RULE)[1].delete(PARENTHESIS.join("|")) end
name()
click to toggle source
# File lib/inci_score/ingredient.rb, line 21 def name return @tokens.first unless parenthesis? @raw.sub(DETAILS_RULE, "").strip end
parenthesis?()
click to toggle source
# File lib/inci_score/ingredient.rb, line 35 def parenthesis? PARENTHESIS.each_slice(2).any? do |pair| pair.all? { |p| @raw.index(p) } end end
synonims()
click to toggle source
# File lib/inci_score/ingredient.rb, line 26 def synonims @tokens[1, @tokens.size].to_a end