Class: KeywordMatcher::Group
- Inherits:
-
Object
- Object
- KeywordMatcher::Group
- Defined in:
- lib/keyword_matcher/group.rb
Constant Summary collapse
- OPERATOR_OR =
'или'.freeze
- OPERATOR_NOT =
'не'.freeze
Instance Attribute Summary collapse
-
#all ⇒ Object
readonly
Returns the value of attribute all.
-
#not ⇒ Object
readonly
Returns the value of attribute not.
-
#or ⇒ Object
readonly
Returns the value of attribute or.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(title) ⇒ Group
constructor
A new instance of Group.
- #not_groups ⇒ Object
- #or_groups ⇒ Object
- #values ⇒ Object
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
#all ⇒ Object (readonly)
Returns the value of attribute all.
3 4 5 |
# File 'lib/keyword_matcher/group.rb', line 3 def all @all end |
#not ⇒ Object (readonly)
Returns the value of attribute not.
3 4 5 |
# File 'lib/keyword_matcher/group.rb', line 3 def not @not end |
#or ⇒ Object (readonly)
Returns the value of attribute or.
3 4 5 |
# File 'lib/keyword_matcher/group.rb', line 3 def or @or end |
#title ⇒ Object (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_groups ⇒ Object
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_groups ⇒ Object
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 |
#values ⇒ Object
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 |