Class: TWFilter::Subject
- Inherits:
-
Object
- Object
- TWFilter::Subject
- Defined in:
- lib/twfilter/subject.rb,
sig/twfilter.rbs
Instance Attribute Summary collapse
-
#policy ⇒ Policy
readonly
Returns the value of attribute policy.
-
#text ⇒ ::String
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #chars ⇒ ::Array[::String]
- #empty? ⇒ Boolean
- #han ⇒ ::Integer
- #han_chars ⇒ ::Array[::String]
- #include?(term) ⇒ Boolean
-
#initialize(text, policy: Policy.corpus) ⇒ Subject
constructor
A new instance of Subject.
- #masked(exceptions) ⇒ ::String
- #ratio ⇒ ::Float
Constructor Details
Instance Attribute Details
#policy ⇒ Policy (readonly)
Returns the value of attribute policy.
5 6 7 |
# File 'lib/twfilter/subject.rb', line 5 def policy @policy end |
#text ⇒ ::String (readonly)
Returns the value of attribute text.
5 6 7 |
# File 'lib/twfilter/subject.rb', line 5 def text @text end |
Instance Method Details
#chars ⇒ ::Array[::String]
12 |
# File 'lib/twfilter/subject.rb', line 12 def chars = @chars ||= text.chars |
#empty? ⇒ Boolean
20 |
# File 'lib/twfilter/subject.rb', line 20 def empty? = text.strip.empty? |
#han ⇒ ::Integer
16 |
# File 'lib/twfilter/subject.rb', line 16 def han = @han ||= han_chars.length |
#han_chars ⇒ ::Array[::String]
14 |
# File 'lib/twfilter/subject.rb', line 14 def han_chars = @han_chars ||= chars.select { |char| Han.char?(char) } |
#include?(term) ⇒ Boolean
22 |
# File 'lib/twfilter/subject.rb', line 22 def include?(term) = text.include?(term) |
#masked(exceptions) ⇒ ::String
24 25 26 |
# File 'lib/twfilter/subject.rb', line 24 def masked(exceptions) exceptions.reduce(text) { |memo, allowed| memo.gsub(allowed, "") } end |
#ratio ⇒ ::Float
18 |
# File 'lib/twfilter/subject.rb', line 18 def ratio = @ratio ||= text.empty? ? 0.0 : han.fdiv(text.length) |