Class: AnyStyle::Feature::Position
- Inherits:
-
AnyStyle::Feature
- Object
- AnyStyle::Feature
- AnyStyle::Feature::Position
- Defined in:
- lib/anystyle/feature/position.rb
Instance Attribute Summary collapse
-
#idx ⇒ Object
readonly
Returns the value of attribute idx.
-
#seq ⇒ Object
readonly
Returns the value of attribute seq.
Attributes inherited from AnyStyle::Feature
Instance Method Summary collapse
-
#initialize(idx: :idx, seq: :seq, **opts) ⇒ Position
constructor
A new instance of Position.
- #observe(token, **opts) ⇒ Object
Methods inherited from AnyStyle::Feature
Methods included from StringUtils
canonize, count, display_chars, display_width, indent, nnum, page_break?, scrub, strip_html, transliterate
Constructor Details
#initialize(idx: :idx, seq: :seq, **opts) ⇒ Position
Returns a new instance of Position.
6 7 8 9 |
# File 'lib/anystyle/feature/position.rb', line 6 def initialize(idx: :idx, seq: :seq, **opts) super(**opts) @idx, @seq = idx, seq end |
Instance Attribute Details
#idx ⇒ Object (readonly)
Returns the value of attribute idx.
4 5 6 |
# File 'lib/anystyle/feature/position.rb', line 4 def idx @idx end |
#seq ⇒ Object (readonly)
Returns the value of attribute seq.
4 5 6 |
# File 'lib/anystyle/feature/position.rb', line 4 def seq @seq end |
Instance Method Details
#observe(token, **opts) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/anystyle/feature/position.rb', line 11 def observe(token, **opts) i = opts[idx] n = opts[seq].size case when i == 0 && i == n - 1 :only when i == 0 :first when i == n - 1 :last else ratio i, n end end |