Class: AnyStyle::Feature

Inherits:
Object
  • Object
show all
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

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

Instance Method Summary collapse

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

#precisionObject (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

Raises:

  • (NotImplementedError)


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