Class: KeywordMatcher::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/keyword_matcher/group.rb

Constant Summary collapse

OPERATOR_OR =
'или'.freeze
OPERATOR_NOT =
'не'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title) ⇒ Group

Returns a new instance of Group.



8
9
10
11
12
13
# File 'lib/keyword_matcher/group.rb', line 8

def initialize(title)
  @title = title
  @all = values
  @or = or_groups
  @not = not_groups
end

Instance Attribute Details

#allObject (readonly)

Returns the value of attribute all.



3
4
5
# File 'lib/keyword_matcher/group.rb', line 3

def all
  @all
end

#notObject (readonly)

Returns the value of attribute not.



3
4
5
# File 'lib/keyword_matcher/group.rb', line 3

def not
  @not
end

#orObject (readonly)

Returns the value of attribute or.



3
4
5
# File 'lib/keyword_matcher/group.rb', line 3

def or
  @or
end

#titleObject (readonly)

Returns the value of attribute title.



3
4
5
# File 'lib/keyword_matcher/group.rb', line 3

def title
  @title
end

Instance Method Details

#not_groupsObject



27
28
29
30
31
32
# File 'lib/keyword_matcher/group.rb', line 27

def not_groups
  return unless title.downcase.match?(/\r?\n#{OPERATOR_NOT}\r?\n/)
  title.downcase.match(/\r?\n#{OPERATOR_NOT}.*/m).to_s.split(OPERATOR_NOT).map do |v|
    v.split("\n").reject(&:blank?).map(&:split)
  end.reject(&:blank?)
end

#or_groupsObject



21
22
23
24
25
# File 'lib/keyword_matcher/group.rb', line 21

def or_groups
  title.downcase.gsub(/\r?\n#{OPERATOR_NOT}.*/m, '').split(OPERATOR_OR).map do |v|
    v.split("\n").reject(&:blank?).map(&:split)
  end.reject(&:blank?)
end

#valuesObject



15
16
17
18
19
# File 'lib/keyword_matcher/group.rb', line 15

def values
  title.downcase.split("\n").map do |line|
    line.split(' ').map(&:strip)
  end.reject(&:empty?)
end