Class: AnyStyle::Feature
- Inherits:
-
Object
- Object
- AnyStyle::Feature
- Includes:
- StringUtils
- Defined in:
- lib/anystyle/feature.rb,
lib/anystyle/feature/ref.rb,
lib/anystyle/feature/caps.rb,
lib/anystyle/feature/line.rb,
lib/anystyle/feature/affix.rb,
lib/anystyle/feature/words.rb,
lib/anystyle/feature/indent.rb,
lib/anystyle/feature/number.rb,
lib/anystyle/feature/quotes.rb,
lib/anystyle/feature/keyword.rb,
lib/anystyle/feature/locator.rb,
lib/anystyle/feature/brackets.rb,
lib/anystyle/feature/category.rb,
lib/anystyle/feature/position.rb,
lib/anystyle/feature/terminal.rb,
lib/anystyle/feature/canonical.rb,
lib/anystyle/feature/dictionary.rb,
lib/anystyle/feature/punctuation.rb
Direct Known Subclasses
Affix, Brackets, Canonical, Caps, Category, Dictionary, Indent, Keyword, Line, Locator, Number, Position, Punctuation, Quotes, Ref, Terminal, Words
Defined Under Namespace
Classes: Affix, Brackets, Canonical, Caps, Category, Dictionary, Indent, Keyword, Line, Locator, Number, Position, Punctuation, Quotes, Ref, Terminal, Words
Instance Attribute Summary collapse
-
#precision ⇒ Object
readonly
Returns the value of attribute precision.
Instance Method Summary collapse
-
#initialize(precision: 10, **opts) ⇒ Feature
constructor
A new instance of Feature.
- #next(idx, seq) ⇒ Object
- #observe(token, **opts) ⇒ Object
- #prev(idx, seq) ⇒ Object
- #ratio(x, y) ⇒ Object
Methods included from StringUtils
canonize, count, display_chars, display_width, indent, nnum, page_break?, scrub, strip_html, transliterate
Constructor Details
#initialize(precision: 10, **opts) ⇒ Feature
Returns a new instance of Feature.
7 8 9 |
# File 'lib/anystyle/feature.rb', line 7 def initialize(precision: 10, **opts) @precision = precision end |
Instance Attribute Details
#precision ⇒ Object (readonly)
Returns the value of attribute precision.
5 6 7 |
# File 'lib/anystyle/feature.rb', line 5 def precision @precision end |
Instance Method Details
#next(idx, seq) ⇒ Object
15 16 17 |
# File 'lib/anystyle/feature.rb', line 15 def next(idx, seq) sequence[idx + 1] end |
#observe(token, **opts) ⇒ Object
11 12 13 |
# File 'lib/anystyle/feature.rb', line 11 def observe(token, **opts) raise NotImplementedError end |
#prev(idx, seq) ⇒ Object
19 20 21 |
# File 'lib/anystyle/feature.rb', line 19 def prev(idx, seq) idx == 0 ? nil : seq[idx - 1] end |
#ratio(x, y) ⇒ Object
23 24 25 |
# File 'lib/anystyle/feature.rb', line 23 def ratio(x, y) (y > 0) ? ((x.to_f / y) * precision).round : 0 end |